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*".
Thanks,
Jimi
Jimi ShermanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FlysterCommented:
Try this macro:
Sub Filter()

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

Open in new window

Flyster
0
byundtMechanical EngineerCommented:
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

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimi ShermanAuthor Commented:
Thanks
Jimi
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.