Solved

Filter multiple criteria with VBA

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
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.

759 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

20 Experts available now in Live!

Get 1:1 Help Now