nniedzielski
Well-known Member
- Joined
- Jan 8, 2016
- Messages
- 598
- Office Version
- 2019
- Platform
- Windows
I am running this macro on a Worksheet called Data, I am doing 3 separate filter and deletes, and i was looking for a solution to combine them into one action, with hopes that it speeds up the macro run time, its currently around 21 seconds, and i think this section is responsible for a good chunk of that.
Note: I have ScreenUpdating off, DisplayEvents off and EnableEvents off
Note: I have ScreenUpdating off, DisplayEvents off and EnableEvents off
VBA Code:
' Filter column AH for Yes
ws.Range("AH1").AutoFilter Field:=34, Criteria1:="1"
' Delete all visible rows except header row
lastRow = ws.Cells(ws.Rows.Count, "AH").End(xlUp).Row
Set visibleRows = ws.Range("AH2:AH" & lastRow).SpecialCells(xlCellTypeVisible)
If Not visibleRows Is Nothing Then visibleRows.EntireRow.Delete
' Remove filter
ws.AutoFilterMode = False
'delete non US
ws.Range("S1").AutoFilter Field:=19, Criteria1:="<>US"
' Delete all visible rows except header row
lastRow = ws.Cells(ws.Rows.Count, "S").End(xlUp).Row
Set visibleRows = ws.Range("S2:S" & lastRow).SpecialCells(xlCellTypeVisible)
If Not visibleRows Is Nothing Then visibleRows.EntireRow.Delete
' Remove filter
ws.AutoFilterMode = False
ws.Range("Y1").AutoFilter Field:=25, Criteria1:="<>US"
' Delete all visible rows except header row
lastRow = ws.Cells(ws.Rows.Count, "y").End(xlUp).Row
Set visibleRows = ws.Range("Y2:Y" & lastRow).SpecialCells(xlCellTypeVisible)
If Not visibleRows Is Nothing Then visibleRows.EntireRow.Delete
' Remove filter
ws.AutoFilterMode = False