Solved

Filter multiple criteria with VBA

Posted on 2013-05-15
4
925 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Outlook Free & Paid Tools
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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