VBA code for more than 2 filter criteria

LC1234

New Member
Joined
Nov 10, 2005
Messages
12
Trying to use autofilter and have more than two criteria, but doesn't seem to like my code. Any suggestions?

Selection.AutoFilter Field:=3, Criteria1:="=North", Operator:=xlOr, _
Criteria2:="=11", Operator:=xlOr, Criteria3:="=22", Operator:=xlOr, _
Criteria4:="=23", Operator:=xlOr, Criteria5:="=30"


Also, when you use only 1 criteria, is records it as Criteria1:="North" but if a second criteria is added, it becomes Criteria1:="=North". Why is the second = sign added?
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
There is no Criteria3 or 4; Autofilter is limited to 2 criteria.

I'm not sure why the equal sign gets added on, but I would suspect it's simply due to the auto syntax checking in VBA.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,168
Messages
5,570,650
Members
412,335
Latest member
cinciri99
Top