AutoFilter Code not working

kc_native

Board Regular
Joined
Jan 20, 2009
Messages
176
I am trying to delete rows in a data sheet, that don't contain the names that I am specifying in the code below, but I am getting "Compile Error: Named argument not found" when I try to run this part of the code. It is highlighting Criteria3:= when it errors out. Is there a limit to the number of criteria you can use in AutoFilter, or am I just not structuring the code correctly? Thanks for any help you can give me!
Code:
With Range("F11:F5000").AutoFilter(Field:=6, Criteria1:="<>Donahue*", Operator:=xlOr, Criteria2:="<>Edgar*", Operator:=xlOr, _
    Criteria3:="<>Honig*", Operator:=xlOr, Criteria4:="<>McHenry*", Operator:=xlOr, Criteria5:="<>Palmer, Robert", _
    Operator:=xlOr, Criteria6:="<>Stockdale*", Operator:=xlOr, Criteria7:="<>Thatcher*", Operator:=xlOr, _
    Criteria8:="<>Wolfe").SpecialCells(xlCellTypeVisible).EntireRow.Delete(xlUp)
End With
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
AutoFilter can have only 2 criteria, manually or in VBA. Use a formula in a spare column and filter on that. Note that you will need AND not OR for not equals.
 
Upvote 0
Hello

This sounds like it calls for an Advanced filter approach ... :)

In any case, Criteria1 and Criteria2 are the only ones you can use for the Autofilter approach. You can filter for the contents of an array, such as for example:

Code:
Sub Autofilter_12a()
     Range("A1").CurrentRegion.AutoFilter _
         Field:=1, _         
         Criteria1:=Array("France", "Belgium", "Germany"), _
         Operator:=xlFilterValues
End Sub
or:
Code:
Sub Autofilter_12b()
     Range("A1").CurrentRegion.AutoFilter _
         Field:=1, _
         Criteria1:=Split("France#Belgium#Germany", "#"), _
         Operator:=xlFilterValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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