Solved

Filter multiple criteria with VBA

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.Range Set 25 78
Excel error  #DIV/0! 7 19
Excel - click on a cell and have everything in another cell clear 13 33
How to run a VBA Macro on Mac Word 2011? 2 34
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…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

831 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