Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Delete all filtered rows from a macro?

Fairly new and plugging my way through macros. On my current macro recording
task, I turn on filtering for all the columns in the second row (top row is a
title line). I set a specific filter on a specific column. I then highlight
and delete all the rows that come up after that filter gets turned on. Then
I turn the specific filter off and continue.

This records in the macro fine, but it wouldn't work week-to-week in real
life, because the rows to be deleted will change each week. When I go and
view the macro code, how can I modify it, after I turn the filter on, to
"delete all the rows shown after filtering"? (Of course I want to keep the
column titles and overall title row too). I basically want to issue some
sort of general command like that rather than highlighting and deleting a
specific range of rows to delete.

I know I can record highlighting the third row and scrolling way down past
where any data would normally be, and then delete, but that just seems like a
sloppy way to do it.

Any help/advice would be much appreciated. Thanks,

Joe
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete all filtered rows from a macro?

One way:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim VisRng As Range

Set wks = ActiveSheet

With wks
With .AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible). Count = 1 Then
MsgBox "only the headers are visible"
Else
'resize to avoid the header
'and come down one row
Set VisRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
VisRng.EntireRow.Delete
End If
End With
End With
End Sub


Joe M wrote:

Fairly new and plugging my way through macros. On my current macro recording
task, I turn on filtering for all the columns in the second row (top row is a
title line). I set a specific filter on a specific column. I then highlight
and delete all the rows that come up after that filter gets turned on. Then
I turn the specific filter off and continue.

This records in the macro fine, but it wouldn't work week-to-week in real
life, because the rows to be deleted will change each week. When I go and
view the macro code, how can I modify it, after I turn the filter on, to
"delete all the rows shown after filtering"? (Of course I want to keep the
column titles and overall title row too). I basically want to issue some
sort of general command like that rather than highlighting and deleting a
specific range of rows to delete.

I know I can record highlighting the third row and scrolling way down past
where any data would normally be, and then delete, but that just seems like a
sloppy way to do it.

Any help/advice would be much appreciated. Thanks,

Joe


--

Dave Peterson
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
cannot delete filtered rows in excel 2007 Cindy E Excel Discussion (Misc queries) 3 October 6th 08 07:09 PM
Delete Filtered Rows in Excel 2007 Moon Excel Discussion (Misc queries) 7 October 2nd 07 03:52 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
Delete Rows Filtered within Auto Filter Gordon[_2_] Excel Programming 1 September 30th 06 10:38 AM
Excel - How do I delete filtered out rows? rook Excel Discussion (Misc queries) 2 November 30th 05 10:45 PM


All times are GMT +1. The time now is 02:30 PM.

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

About Us

"It's about Microsoft Excel"