On Error Resume Next - cover all autofilter criteria

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
186
Office Version
  1. 2013
Hi All

Just a quick one - can I check the error handler covers all my autofilter criteria? I can't avoid the errors occurring on any of the criteria, I just want to skip over.

Code:
Sub DataRaw()
    Sheets("DataInput").Select
    
    On Error Resume Next
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=11, Criteria1:= _
        "=Waste", Operator:=xlAnd
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=14, Criteria1:=">0", _
        Operator:=xlAnd
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=1, Criteria1:=Array("<>*cost*", _
        "<>*refurb*", _
        "<>*rfbr*"), _
        
        Operator:=xlFilterValues
    On Error GoTo 0
    
End Sub

Many Thanks
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Just for your info, the filter on Field 1 will never work, as you cannot filter on more than two criteria when using non-exact matches.
 
Upvote 0
@Fluff Thanks for that gem of info, I wasn't aware of that from my research.

I'm fortunate that my Source data is only temporary then wiped so I have changed the code to delete those rows before filtering on other criteria:

Code:
 Sub DataRaw()

    Sheets("DataInput").Select
    
    On Error Resume Next
    
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=4, Criteria1:= _
        "=*cost*", Operator:=xlOr, Criteria2:="=*spare*"
    Range("$A$2:$W$20000").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.EntireRow.Delete
    
    Selection.AutoFilter
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=4, Criteria1:= _
        "=*refb*", Operator:=xlOr, Criteria2:="=*refurb*"
    Range("$A$2:$W$20000").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.EntireRow.Delete
    
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=11, Criteria1:= _
        "=Waste", Operator:=xlAnd
    ActiveSheet.Range("$A$2:$W$20000").AutoFilter Field:=14, Criteria1:=">0", _
        Operator:=xlAnd
    
    On Error GoTo 0
 
Last edited:
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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