Solved

Filter multiple criteria with VBA

Posted on 2013-05-15
4
943 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

734 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