Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 13
Default Delete rows autofilter range problem

Hi and thanks in advance,

I am using Excel 2003

I have a delete rows macro that tests whether there is data in one or more user defined columns on the sheet and if not, places an "X" in the first blank column to the right of the data. I then apply an autofilter to pick up all rows with an "X" and then would like to delete all the filtered rows except the first one in the range which is a header row. The first row of data may be any row on the sheet as defined by the user via a userform.

The code below works fine if there is no data in row 65,536, the last row on the worksheet. If there is a value in the last row then the macro does not delete the filtered rows as required. When the user defines a range that includes all rows on the sheet, from 1 to 65,536, I think Excel changes the range address to a column reference eg. "A : D" instead of the full address "A1 : D65536" so that when you apply the offset method it offsets to the wrong row. Any ideas?

With rRange
.AutoFilter Field:=mLastCol + 1, Criteria1:="X"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delet e
End With
  #2   Report Post  
Junior Member
 
Posts: 13
Default

I finally managed to get it working by adapting someone's code ...


Code:
 rRange.AutoFilter Field:=mLastCol + 1, Criteria1:="X"
Set rng = ActiveSheet.Range(Cells(StartRow+1, StartCol), Cells(EndRow, EndCol + 1))
rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Quote:
Originally Posted by deutz View Post
Hi and thanks in advance,

I am using Excel 2003

I have a delete rows macro that tests whether there is data in one or more user defined columns on the sheet and if not, places an "X" in the first blank column to the right of the data. I then apply an autofilter to pick up all rows with an "X" and then would like to delete all the filtered rows except the first one in the range which is a header row. The first row of data may be any row on the sheet as defined by the user via a userform.

The code below works fine if there is no data in row 65,536, the last row on the worksheet. If there is a value in the last row then the macro does not delete the filtered rows as required. When the user defines a range that includes all rows on the sheet, from 1 to 65,536, I think Excel changes the range address to a column reference eg. "A : D" instead of the full address "A1 : D65536" so that when you apply the offset method it offsets to the wrong row. Any ideas?

With rRange
.AutoFilter Field:=mLastCol + 1, Criteria1:="X"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delet e
End With
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
after autofilter/delete rows left not visible John Keith Excel Programming 1 January 13th 09 04:37 PM
delete rows from AutoFilter or Advanced Filter range Gareth[_2_] Excel Programming 1 January 7th 09 01:01 PM
AutoFilter code to delete rows Hans Knudsen Excel Programming 4 October 31st 08 03:41 PM
Delete Rows with Autofilter and partial cell. [email protected] Excel Programming 1 June 29th 07 08:20 PM
delete rows autofilter masterphilch Excel Programming 3 January 5th 05 08:07 PM


All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"