Run-time error '1004': Application-defined or object-defined error

Damian37

Active Member
Joined
Jun 9, 2014
Messages
301
Office Version
  1. 365
Hi,
I'm trying to select multiple criteria within the same column from my data set. I continue to receive a 1004 Run-time error for the following code. When I select debug the following line highlights:
Sheets("Report Data").Range("E1:E").AutoFilter Field:=5, Criteria1:=criteriaArray, _
Operator:=xlFilterValues
I've been unable to figure out how to properly utilize an array within my code:

VBA Code:
Sub FilterMultipleCriteria()
'
 '   On Error Resume Next
    
' Filter by Multiple Criteria
    Dim ws As Worksheet
    Dim FilterRange As Range
    Dim criteriaArray As Variant
    
    Set ws = ThisWorkbook.Sheets("Report Data")
    Set FilterRange = ws.Range("E1:E" & ws.Cells(ws.Rows.Count, "E").End(xlUp).Row)
    
        criteriaArray = Array("High", "Moderate-High")
    
    With ws
        .AutoFilterMode = False
        Sheets("Report Data").Range("E1:E").AutoFilter Field:=5, Criteria1:=criteriaArray, _
        Operator:=xlFilterValues
        End With
    
'    If Err.Numer <> 0 Then
 '       MsgBox "Error: " & _
'Err.Description
 '   End If
        
    End Sub

Any help is greatly appreciated! Thank you so much.
D.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Change the code line:
Code:
Sheets("Report Data").Range("E1:E").AutoFilter Field:=5, Criteria1:=criteriaArray, Operator:=xlFilterValues
to:
VBA Code:
FilterRange.AutoFilter Field:=1, Criteria1:=criteriaArray, Operator:=xlFilterValues
 
Upvote 0
Solution
Change the code line:
Code:
Sheets("Report Data").Range("E1:E").AutoFilter Field:=5, Criteria1:=criteriaArray, Operator:=xlFilterValues
to:
VBA Code:
FilterRange.AutoFilter Field:=1, Criteria1:=criteriaArray, Operator:=xlFilterValues
Thanks Rollis13,
I tried that, but received the same message. I'm sure it has something to do with the way I'm setting the criteriaArray that is causing the code not to recognize the values. I just haven't been able to figure it out yet.
D.
 
Upvote 0
Change the code line:
Code:
Sheets("Report Data").Range("E1:E").AutoFilter Field:=5, Criteria1:=criteriaArray, Operator:=xlFilterValues
to:
VBA Code:
FilterRange.AutoFilter Field:=1, Criteria1:=criteriaArray, Operator:=xlFilterValues
I take it back. I didn't realize the FilterRange line was identifying the Field so I was using the value 5, because that's the column number for E. Once I set the Field to value = 1 the code worked like a charm. Thank you very much for your help!

D.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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