I have a macro in Excel VBA and one of the steps within it is performing an AutoFilter on the ActiveSheet range, filter based on color. This step seems quite time consuming and I am wondering if there might be a quicker way to filter my data? Is filtering on color usually slower? here's a sample of the code that I am using:
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AB$100000").AutoFilter Field:=1, Criteria1:=RGB(255 _
, 199, 206), Operator:=xlFilterCellColor
Rows("2:100000").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Can you try this. Define the last row of data and don't select. I'm not sure it will make a huge difference but see how it goes.
Sub Macro1()
Dim r As Long
r = Range("A" & Rows.Count).End(xlUp).Row
With ActiveSheet.Range("$A$1:$AB$" & r)
.AutoFilter Field:=1, Criteria1:=RGB(255, 199, 206), Operator:=xlFilterCellColor
.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete shift:=xlUp
End With
ActiveSheet.AutoFilterMode = False
End Sub
You don't need to select.
Sub DoIt()
Dim rng As Range
Set rng = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
rng.AutoFilter Field:=1, Criteria1:=RGB(255, 199, 206), Operator:=xlFilterCellColor
rng.Offset(1).EntireRow.Delete
ActiveSheet.AutoFilterMode = 0
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.