How to make a macro auto-filter multiple criteria?

Hi, I need to make a macro with an auto-filter using multiple criteria in column A.
The multiple criteria are "S*" and "P*".
Jimi ShermanAsked:
Who is Participating?
byundtConnect With a Mentor Commented:
Although you can use the Or operator to filter two items, that approach breaks when you want a third. The Array method in the macro below allows you to add as many items as you like to the filter.
Sub AutofilterGenie()
Dim rg As Range
Set rg = Range("A1")            'Header label for column A
rg.AutoFilter                   'Remove any existing AutoFilter
Set rg = Range(rg, Cells(Rows.Count, rg.Column).End(xlUp))  'All the data in column A
rg.AutoFilter Field:=1, Criteria1:=Array("S*", "P*"), Operator:=xlFilterValues
End Sub

Open in new window

Try this macro:
Sub Filter()

    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:="=P", _
        Operator:=xlOr, Criteria2:="=S"
End Sub

Open in new window

Jimi ShermanAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.