Reputation: 71
I have the below code which will delete rows based on criteria in column I:
Sub Strip()
Dim rng As Range
With ActiveSheet
.Columns("I").AutoFilter Field:=1, Criteria1:="=70-79%", VisibleDropDown:=False
Set rng = .AutoFilter.Range
End With
If rng.Columns("I").SpecialCells(xlCellTypeVisible).Count - 1 > 0 Then
Application.DisplayAlerts = False
rng.Offset(1, 0).SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
End If
rng.AutoFilter
End Sub
I have about 100
different criteria that I want to act on in this way. I'd rather not have to repeat this code 100
times, and so can anyone tell me how to code this in the form of an array? I've tried various methods but can't seem to get it to work.
Upvotes: 4
Views: 2488
Reputation: 149295
Use
.Columns("I").AutoFilter Field:=1, Criteria1:=MyArray, Operator:=xlFilterValues
Where MyArray
is a string Array
Example
Dim MyArray(1 To 4) As String
MyArray(1) = "This"
MyArray(2) = "is"
MyArray(3) = "an"
MyArray(4) = "array"
'
'~~> Rest of code
'
.Columns("I").AutoFilter Field:=1, Criteria1:=MyArray, Operator:=xlFilterValues
'
'~~> Rest of code
'
Screenshot
Upvotes: 6