RunTime Error 1004 When Auning AutoFilter
Results 1 to 3 of 3

Thread: RunTime Error 1004 When Auning AutoFilter
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jul 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default RunTime Error 1004 When Auning AutoFilter

    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

  2. #2
    Board Regular
    Join Date
    Jul 2012
    Location
    Hampshire, UK
    Posts
    4,931
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default Re: RunTime Error 1004 When Auning AutoFilter

    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

  3. #3
    New Member
    Join Date
    Jul 2019
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: RunTime Error 1004 When Auning AutoFilter

    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

    Quote Originally Posted by dmt32 View Post
    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •