VBA autofilter multiple criteria

teatimecrumpet

Active Member
Joined
Jun 23, 2010
Messages
307
Hi,

I'm trying to autofilter a list for multiple criteria. But I'll get a "Run-Time Error '1004': Application-defined or object-defined error". I believe it has something to do with some criteria not showing up in the filter field. Is there a way to filter if found but not then ignore?

With Sheets("Preliminary")
.AutoFilterMode = False

.Range("A1:L1").AutoFilter
.Range("A1:L1").AutoFilter Field:=2, Criteria1:="254939457", _
Operator:=xlAnd, Criteria2:="254939341", _
Operator:=xlAnd, Criteria3:="254939382", _
Operator:=xlAnd, Criteria4:="254939416", _
Operator:=xlAnd, Criteria5:="254939325", _
Operator:=xlAnd, Criteria6:="254939887", _
Operator:=xlAnd, Criteria7:="254939317", _
Operator:=xlAnd, Criteria8:="254939390", _
Operator:=xlAnd, Criteria9:="254939374", _
Operator:=xlAnd, Criteria10:="254939333"



End With


thanks,
Mike
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi guys,

This semi-recorded seems to work. It's for two different columns with different sets of filter criteria. Haven't used arrays before but it seems to be the key for this type of filter manipulation.

Hope this helps someone.

With Sheets("Preliminary")
.Range("$A$1:$N$8000").AutoFilter Field:=1, Criteria1:=Array( _
"value", "value", "value", _
"value", "value", "value", _
"value", "value", "value", "value", _
"value", "value"), Operator:=xlFilterValues


.Range("$A$1:$N$8000").AutoFilter Field:=14, Criteria1:=Array( _
"02878", "02881", "02886", _
"02884", "02889", _
"02880", "02888", _
"02879", "02882", "02887"), Operator:=xlFilterValues

End With
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,861
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top