RunTime Error 1004 When Auning AutoFilter

Bwolosz

New Member
Joined
Jul 10, 2019
Messages
6
Good Morning Everyone,

Looking for some recommendations on how I could prevent the RunTime Error 1004 while running VBA for an AutoFilter routine.

In the work sheet I have a ActiveX Combobox that is being used to select a value.
I would then like to filter records in a range of "A15:F" & LRow ( Last Row )
The code is being run on the selection of a new value in the ComboBox

Below is the code I have been working with.




Private Sub ComboBox1_Change()


Dim ComboVal As Long
Dim LRow As Long


LRow = Sheets("Labor_Entry_Form").Cells(Rows.Count, "A").End(xlUp).Row
ComboVal = ComboBox1.Value


With Sheets("Labor_Entry_Form")
.AutoFilterMode = False
.Range("A15:F" & LRow).AutoFilter
.Range("A15:F" & LRow).AutoFilter Field:=1, Criteria1:=ComboVal
End With




End Sub


Any help is greatly appreciated.

Thanks,

Bradley
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,
try this update to your code

Code:
Private Sub ComboBox1_Change()
    Dim ComboVal As String
    Dim LRow As Long
    
    With Me.ComboBox1
        If .ListIndex = -1 Then Exit Sub
        ComboVal = .Value
    End With
    
    With Sheets("Labor_Entry_Form")
'add password as required
        .Unprotect Password = ""
        LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        With .Range("A15:F" & LRow)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:=ComboVal
        End With
    End With
    
End Sub

Dave
 
Upvote 0
Thanks for the suggestion Dave.
I tried the code and am still receiving the same 1004 error.

I just tried to run the code against a filter button I added to the sheet, and everything seems to work fine?!?!

I really do appreciate your attempt to help.

Thanks,

Bradley

Hi,
try this update to your code

Code:
Private Sub ComboBox1_Change()
    Dim ComboVal As String
    Dim LRow As Long
    
    With Me.ComboBox1
        If .ListIndex = -1 Then Exit Sub
        ComboVal = .Value
    End With
    
    With Sheets("Labor_Entry_Form")
'add password as required
        .Unprotect Password = ""
        LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        With .Range("A15:F" & LRow)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:=ComboVal
        End With
    End With
    
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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