Solved

Filter multiple criteria with VBA

Posted on 2013-05-15
4
900 Views
Last Modified: 2013-05-15
ActiveSheet.Range("$B$3:$C$523").AutoFilter Field:=1
    ActiveSheet.Range("$B$3:$C$523").AutoFilter Field:=1, Criteria1:=Array( _
        "ACKLANDS*", "ARTISTS*", "AVANDIUM*", _
        "BASIN*", "BIG*", "BONDY*"), Operator:=xlFilterValues

Open in new window


Hi,

I have the above line of code which is not working. What I want is to have a filtered list which has all of the words which starts with the words in the above array.

When I run the cide, it just hides all data although there are clearly data available to be filtered.

Any help is much appreciated!
0
Comment
Question by:Shanan212
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Barry62
ID: 39168933
Could you give us some data so we can debug your code?
0
 
LVL 13

Author Comment

by:Shanan212
ID: 39168962
Hi,

See attached for the sample sheet.
Sample-Data.xlsx
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39169299
Your trick apparently doesn't work with wild cards. You should therefore consider either Advanced Filter or an auxiliary column.

I put the first word in each cell from column B in column D (the auxiliary column). I then used the Array trick on that column, and it worked. Note that I removed the * wildcard character from each word.
Sub FilterMe()
ActiveSheet.Range("$B$3:$D$523").AutoFilter
ActiveSheet.Range("$B$3:$D$523").AutoFilter Field:=3, _
    Criteria1:=Array("ACKLANDS", "ARTISTS", "AVANDIUM", "BASIN", "BIG", "BONDY"), _
    Operator:=xlFilterValues
End Sub

Open in new window

Sample-DataQ28129056.xlsm
0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 39169374
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now