473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB.NET Excel Special Cells and AutoFilter problems

Hi

I'm trying to format an Excel file from within VB.NET 2008 (Framework 2.0).

I'm not very familiar with Excel but have taken existing working code from an old VB6 program and am "tweaking" it to get it to work in VB.NET.

I have most of it working with the exception of the following lines:

rng = ws.Range(xclApp.Intersect(ws.Rows(7).EntireRow, ws.UsedRange.Columns(1)), ws.UsedRange.SpecialCells(XlCellType.xlCellTypeLas tCell))
rng.Value = rng.Value

'Works correctly up until above line (no cells found for the following)

'For Each cel In rng.Offset(1).SpecialCells(XlCellType.xlCellTypeAl lFormatConditions, Type.Missing)
' If Trim(cel) = "" Then cel = cel.Offset(-1).Value
'Next cel

'rng.Worksheet.AutoFilterMode = False
'rng.AutoFilter(Field:=12, Criteria1:="<>*Total*", Operator:=XlAutoFilterOperator.xlOr, Criteria2:="=*Grand*")
'rng.Offset(1).SpecialCells(XlCellType.xlCellTypeV isible).EntireRow.Delete(Shift:=XlDirection.xlUp)
'rng.Value = rng.Value
''rng.AutoFilter()
'rng.Worksheet.AutoFilterMode = False

'--------------------------------------------------------------------

rng.Font.Bold = False

Hope someone can help me get this going....
Aug 31 '08 #1
1 5120
Sorry I didn't explain the problem with the following portion:

'rng.Worksheet.AutoFilterMode = False
'rng.AutoFilter(Field:=12, Criteria1:="<>*Total*", Operator:=XlAutoFilterOperator.xlOr, Criteria2:="=*Grand*")
'rng.Offset(1).SpecialCells(XlCellType.xlCellTypeV isible).EntireRow.Delete(Shift:=XlDirection.xlUp)
'rng.Value = rng.Value
''rng.AutoFilter()
'rng.Worksheet.AutoFilterMode = False

This is supposed to filter through and only delete certain lines based on the criteria given.

It deletes those lines but I also lose all the data in all of the fields with the exception of field 12.
Aug 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ST | last post by:
Hi, I'm having problems opening up excel thru my code. It will write and saveas an excel file, but the application won't open on the user's computer, excel seems to be hidden, because it shows up...
5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
2
by: krigare | last post by:
Hope this is the right place to post :-) I am trying to use an Excel COM object via PHP. I am able to read/write data to cells, use AutoFilter, and AutoFit on columns. I can even set the cell...
9
by: John Brock | last post by:
I am trying to create a workbook where one of the worksheets contains an AutoFiltered table. It looks like it should be simple -- what I am doing is this: rng = ws.Range("MyTableRange")...
1
by: doug9149 | last post by:
Hello all, I've got some code I wrote using VBA for Excel that I'm trying to recreate using C#.NET. The code autofilters 1 entire column from 1 Worksheet from a Workbook and then appends this...
1
by: cterner | last post by:
I have a very basic understanding of VB and am attempting to initiate a procedure upon data entry into specific cells. Specifically, I want to perform 2 different inplace advance filter searches...
1
by: jonathanD | last post by:
Excel Gurus, I am suffering with a problem with the following Code Me.ListBox1.List = Range("a1:f10").Cells.SpecialCells_(xlCellTypeVisible).VALUE The listbox will popoulate...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.