MORE THAN ONE CRITERIA IN FILTERS USING VBA

Hi,

How i modify the criteria in the range.autofilter in vba.

For example:

I have a column and i want to filter for the fields that contains "Michelle or Jessica or Wanda" and another column that contains in a cell two texts (ex: the car is blue) so the filter can find that the cells contains car and blue, so the filter present all the cells that contains car and blue in the same cell. Any idea?
LVL 1
joyacv2Asked:
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.

Harry LeeCommented:
Use the following code.

Which column contains the People Name, and which column contains the Car and Blue?

You have to use something similar to the following code.

Sub AutoFilterMultiCriterias()
    rw = Cells(Rows.Count, 1).End(xlUp).Row
    clmn = Cells(1, Columns.Count).End(xlToLeft).Column
    ActiveSheet.Range(Cells(1, 1), Cells(rw, clmn)).Select
    ActiveSheet.Range(Cells(1, 1), Cells(rw, clmn)).AutoFilter Field:=1, Criteria1:=Array( _
        "Jessica", "Michelle", "Wanda"), Operator:=xlFilterValues
    ActiveSheet.Range(Cells(1, 1), Cells(rw, clmn)).AutoFilter Field:=2, Criteria1:="=*Car*", Operator:=xlAnd, Criteria2:="=*Blue*"
End Sub

Open in new window

0

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
byundtMechanical EngineerCommented:
HarryHYLee,
Nicely done!

Brad
0
joyacv2Author Commented:
perfect code, i make a little modifications to use in my code
0
Harry LeeCommented:
Glad I can help.
0
normajm400Commented:
If you are using Excel 2007 or better, convert the data to a table using the "Format as Table" option on the ribbon.  Tables allow for multiple column filters.
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.