thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
442
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

Is there a way to delete all the rows int he selected autofilter in the below code. At the moment it only looks as rows 2:29.

Thanks

Code:
Sub Macro1()

    ActiveSheet.ListObjects("Brecon_Mail_Merge").Range.AutoFilter Field:=12, _
        Criteria1:="Non Ford"
    Rows("2:29").Select
    Selection.Delete Shift:=xlUp
    Range("Brecon_Mail_Merge[[#Headers],[Column1]]").Select
    Selection.AutoFilter
    Selection.AutoFilter
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Some time ago, I put together some macros that I put in my Personal Macro Workbook to delete rows return by filters, or to delete rows hidden by filters.
Here is the one that deletes the unhidden rows. So, after running your filter, you could just call this macro.
Code:
Public Sub DeleteUnHiddenRows()
'   Deletes all unhidden rows except for the header (first row only)

    Application.DisplayAlerts = False
    ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
    Application.DisplayAlerts = True

End Sub
 
Upvote 0
Do you happen to have the one to delete the rows hidden from filter?
Sure. Here it is:
Code:
Public Sub DeleteHiddenRows()
'   Deletes all hidden rows on a sheet
    
    Dim lRows As Long
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    For lRows = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
        If Cells(lRows, 1).EntireRow.Hidden = True Then Cells(lRows, 1).EntireRow.Delete
    Next lRows
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,796
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top