Programming Autofilter

C

ChrisBat

HELP!! I'm on my third Starbucks venti coffee today, and I'm still
stumped on this problem.
I'm trying to build a macro that will allow me to filter on more than
the normally allowed 2 criteria using the Autofilter. Say my list had
two columns, and the first column was 250 items long (which changes
from
week to week), containing various food and drinks. I want to be able
to
filter on:
*apple (pulling up apple, pineapple)
*cola (pulling up Coca-Cola, Pepsi-Cola, RC Cola)
*fish* (pulling up swordfish, fishmeal)
and
*juice (pulling up orange juice, grape juice).
The macro should be able to pull up the above, without me having to
use
two different autofilters (first for the first two and the second for
the second two).
Beyond this, I would like to be able to pull up the above criteria but
then using a filter on the second column, pull up more specific data,
for example the second column being Countries Exported to, and the
criteria being
Canada
U.S.
Angola
Ireland.
Does anyone have any suggestions?
The following is the syntax that I have tried up to this point, but it
only allows me two criteria per filter.

Sub Macro3()

Selection.AutoFilter
Selection.AutoFilter Field:=1, _
Criteria1:="=*apple*", Operator:=xlOr, _
Criteria2:="=*cola*", Operator:=xlOr, _
Criteria3:="=*fish*", Operator:=xlOr, _
Criteria4:="=*juice*"

Selection.AutoFilter Field:=2, _
Criteria1:="Canada", Operator:=xlOr, _
Criteria2:="U.S.", Operator:=xlOr, _
Criteria3:="Angola", Operator:=xlOr, _
Criteria4:="Ireland"
End Sub
 
A

Arvi Laanemets

Hi

With Autofilter set on, you can select Custom, and set up to 2 values to be
filtered. I.e. you can set the autofilter to 'apple' OR 'pineapple', and to
'Coca-Cola' OR 'Pepsi-Cola'.
No 3d option there - sorry! But you can set the custom filter p.e. to
'*Cola', thus filtering all entries ending with 'Cola'.


Arvi Laanemets
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top