How to handle Error 1004 in Autofilter Multiple Criteria

petes

Board Regular
Joined
Sep 12, 2009
Messages
168
Hi Guys -

I have this code. The 2nd part fails (Doesn't move to EFCFilter on error) whenever there is no matching filter criteria in 1st part. But, runs perfectly if there is matching filter criteria found in 1st part. Any thought?

Code:
[B]'--------------------------1st Part----------------------------------------------[/B] 
On Error GoTo ACT2


   AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=18, Criteria1:="False"
       
ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True

[B]'--------------------------2nd Part----------------------------------------------[/B]
ACT2:
On Error GoTo EFCFilter
    
    AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=18, Criteria1:="=#N/A"
       
ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True

Note: I don't want to combine multiple criteria. I need it separately as is.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hard to give specific advice as we don't know ..
- the object of the code
- the full code
- what the data is like

However, the following is not right.
Rich (BB code):
AutoFilterMode = False
The syntax for AutoFilterMode is (from Help)
Syntax
expression. AutoFilterMode

expression A variable that represents a Worksheet object.
You do not have the qualifying Worksheet object. It would need to be something like
Rich (BB code):
ActiveSheet.AutoFilterMode = False
 
Last edited:
Upvote 0
Sorry about that! Here is the full code. Each part fails if there is no matching criteria in previous part and also in the current part. Hope its not confusing.

Code:
Sub FilterTEST()
   
'--------------------------1st Part-----------------------------------------------
  
On Error GoTo ACT2


   AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=18, Criteria1:="False"
       
ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True


ACT2:
On Error GoTo EFCFilter
    
    AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=18, Criteria1:="=#N/A"
       
ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True


'--------------------------2nd Part------------------------------------------------


EFCFilter:
On Error GoTo EFC2


    AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=22, Criteria1:="False"
    
rSource.Resize(rSource.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True
    
EFC2:
On Error GoTo BUDGETFilter


AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=22, Criteria1:="=#N/A"
       
rSource.Resize(rSource.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True


'--------------------------3rd part-----------------------------------------------------


BUDGETFilter:
On Error GoTo BGT2


    AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=26, Criteria1:="False"
      
rSource.Resize(rSource.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True


BGT2:
On Error GoTo ENDFilter
AutoFilterMode = False
    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=26, Criteria1:="=#N/A"
      
rSource.Resize(rSource.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Select
With Selection.Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.Font.Bold = True


'--------------------------End-----------------------------------------------------	


ENDFilter:
    Range("A1").Select
    Selection.AutoFilter
  
End Sub
 
Upvote 0
Glad you found it useful! :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
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