473,594 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET Excel Special Cells and AutoFilter problems

2 New Member
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.R ows(7).EntireRo w, ws.UsedRange.Co lumns(1)), ws.UsedRange.Sp ecialCells(XlCe llType.xlCellTy peLastCell))
rng.Value = rng.Value

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

'For Each cel In rng.Offset(1).S pecialCells(XlC ellType.xlCellT ypeAllFormatCon ditions, Type.Missing)
' If Trim(cel) = "" Then cel = cel.Offset(-1).Value
'Next cel

'rng.Worksheet. AutoFilterMode = False
'rng.AutoFilter (Field:=12, Criteria1:="<>* Total*", Operator:=XlAut oFilterOperator .xlOr, Criteria2:="=*G rand*")
'rng.Offset(1). SpecialCells(Xl CellType.xlCell TypeVisible).En tireRow.Delete( Shift:=XlDirect ion.xlUp)
'rng.Value = rng.Value
''rng.AutoFilte r()
'rng.Worksheet. AutoFilterMode = False

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

rng.Font.Bold = False

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

'rng.Worksheet. AutoFilterMode = False
'rng.AutoFilter (Field:=12, Criteria1:="<>* Total*", Operator:=XlAut oFilterOperator .xlOr, Criteria2:="=*G rand*")
'rng.Offset(1). SpecialCells(Xl CellType.xlCell TypeV isible).EntireR ow.Delete(Shift :=XlDirection.x lUp)
'rng.Value = rng.Value
''rng.AutoFilte r()
'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
3112
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 on the task manager. The problem is, if this user tries to download the data more than once, it gets stuck because the file already exists, so I want it to overwrite the old file...but the user can't overwrite when the excel app won't work! Any...
5
4072
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 data to export into Excel in a certain format, i.e it needs to begin importing at cell A4, and in truth it would be great
2
5425
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 recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
2
3646
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 background color. However, I am having problems with setting borders on cells and making a column have centered text. I am able to do this with PERL. So, I am looking for a an expert to tell me how to do it in PHP (I am a noob with PHP).
9
13818
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") rng.AutoFilter() Unfortunately I get an exception on the second statement, with the unhelpful message:
1
8183
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 filtered code to a new column in a new Worksheet in a new Workbook. First, the VBA code: Set rData = wsData.Range("BQ5", wsData.Range("BQ65536").End(xlUp)) Set rTargetCl = wsTarget.Range("B65536").End(xlUp).Offset(1,0) With rData .AutoFilter...
1
1203
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 based upon what is entered into cells A1 or cell B1. I found a script that does this and it works for my application: Private Sub Worksheet_Change(ByVal Target As Range) ActiveCell.Offset(1, 0).Range("A1").Select If Target.Address = "$A$1" Or _ ...
1
4932
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 however as soon as the range is autofiltered, only the first line of the autofiltered data will be displayed rather than the entire autofilter range.
10
9662
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 each tab and apply autowidth to columns and apply autofilter to the first row of every tab in the workbook. I've this down
0
7947
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.