Multiple filtering criteria results in no cells being found

BillTony

Board Regular
Joined
May 3, 2017
Messages
70
I am using VB to delete rows meeting certain criteria - however, if the criteria is NOT met, I'm receiving a Run-time 1004 - No cells were found.

The code below will result in a match on Criteria 1, but there is no match on Criteria 2 (often, that is...).

In the event that this occurs, I would like to simply SHOW ALL DATA and move on.

But, as the code is basically telling it to do something that can't be done (at least as I've written it...), it errors out.

Code:
'Set the RANGE and FILTERING CRITERIA.
    ActiveSheet.Range("$A$1:$ZZ" & Last_Row_ColA).AutoFilter Field:=41, Criteria1:= _
        "EXC"
       
'Set the RANGE and FILTERING CRITERIA.
    ActiveSheet.Range("$A$1:$ZZ" & Last_Row_ColA).AutoFilter Field:=9, Criteria1:= _
        "Discontinued"
 
'Set the RANGE - DELETE all VISIBLE CELLS.
    'ActiveSheet.Range("$A$2:$ZZ" & Last_Row_ColA).SpecialCells(xlCellTypeVisible).Select
   
'DELETE the ROWS.
    'Selection.Delete shift:=xlUp
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hia
How about this
Code:
    If WorksheetFunction.CountIf(ActiveSheet.Range("I1:I" & Last_Row_ColA), "Discontinued") >= 1 Then
'Set the RANGE and FILTERING CRITERIA.
    ActiveSheet.Range("$A$1:$ZZ" & Last_Row_ColA).AutoFilter Field:=41, Criteria1:= _
        "EXC"
       
'Set the RANGE and FILTERING CRITERIA.
    ActiveSheet.Range("$A$1:$ZZ" & Last_Row_ColA).AutoFilter Field:=9, Criteria1:= _
        "Discontinued"
 
'Set the RANGE - DELETE all VISIBLE CELLS.
    'ActiveSheet.Range("$A$2:$ZZ" & Last_Row_ColA).SpecialCells(xlCellTypeVisible).Select
   
'DELETE the ROWS.
    'Selection.Delete shift:=xlUp
    End If
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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