On Error Resume Next - cover all autofilter criteria

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
181
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:

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,012
Office Version
  1. 365
Platform
  1. Windows
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.
 

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
181
Office Version
  1. 2013
@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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,012
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,738
Messages
5,597,829
Members
414,180
Latest member
Sir Khaya

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
Top