macro for 4 constraints in autofilter

G

Guest

Hi

Not sure if this is possible, or if I have tackled this the right way so any
help greatly appreciated! I am (trying to) write a macro that will use
multiple constraints (in 1 column) in autofilter, this is so that I don't
have to use the advanced filter option. The result of the macro should return
rows that contain "19" or "20" or "act" or "regul" in the 3rd field, and hide
the rows that don't. My macro that is not working at the moment:

'
Sheets("Agr-Tra").Select
Selection.AutoFilter Field:=3, Criteria1:="=regul*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=act*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=19*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=20*"
End Sub

This is returning 0 rows with the above criteria, which is incorrect as it
should be over 300 rows.

Much appreciated
Gus
 
G

Guest

You dont need a macro
the simplest way to do this is to set up a helper column with
=if(or(C1=19,C1=20,C1="act",C1="regul"),1,0)
and use normal autofilter on this column.
 

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