Announcement

Collapse
No announcement yet.

Run-time error '1004: AutoFilter method of Range class failed

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run-time error '1004: AutoFilter method of Range class failed



    Hello,

    Im trying to use a combo box to filter data on another sheet this is what I have and it gives me the Run-time error '1004: AutoFilter method of Range class failed error.
    Code:
    Private Sub ComboBox1_Change()
        Application.ScreenUpdating = False
        If Sheets("Sheet3").AutoFilterMode = True Then Sheets("Sheet3").Range("d1:d6000").End(xlUp).AutoFilter
        Sheets("Sheet3").Range("d1:d6000").End(xlUp).AutoFilter Field:=4, Criteria1:=ComboBox1.Value, visibledropdown:=False
        Application.ScreenUpdating = True
         
    End Sub
    any ideas why
    Last edited by S M C; September 20th, 2011, 05:12. Reason: Code Tags

  • #2
    Re: Run-time error '1004: AutoFilter method of Range class failed

    Welcome to the Ozgrid community.

    Please take the time to become familar with the Forum Rules so as to avoid infractions that may impact your posting privilege. After all, you agreed to follow them when you subscribed here.

    Per the Forum Rules, all VBA code must be wrapped in code tags, which you omitted. I have added them for you. Please take the time read and understand the rules.

    Wrap your codes with code tags. Using code tags improve readability.

    Future posts that omit code tags ( or other rules violations) may result in your thread being locked or deleted.
    Cheers,

    S M C

    Click To Read: How To Use Tags In Your Threads/Posts
    Please take time to read Forum Rules before posting
    Message To Cross Posters

    Comment


    • #3


      Re: Run-time error '1004: AutoFilter method of Range class failed

      Try

      Code:
      Private Sub ComboBox1_Change()
      
          Application.ScreenUpdating = False
          Sheets("Sheet3").AutoFilterMode = False
          Sheets("Sheet3").Range("d1:d6000").AutoFilter Field:=1, Criteria1:=ComboBox1.Value, visibledropdown:=False
          Application.ScreenUpdating = True
           
      End Sub
      OR
      Code:
      Private Sub ComboBox1_Change()
      
          Application.ScreenUpdating = False
          Sheets("Sheet3").AutoFilterMode = False
          Sheets("Sheet3").Range("A1:D6000").AutoFilter Field:=4, Criteria1:=ComboBox1.Value, visibledropdown:=False
          Application.ScreenUpdating = True
           
      End Sub
      IN the first one, the range has only one column, and so you cannot specify a field as 4
      In the second one, the range has 4 columns, ie, from A to D, and here you can specify any field from 1 to 4

      HTH
      Cheers,

      S M C

      Click To Read: How To Use Tags In Your Threads/Posts
      Please take time to read Forum Rules before posting
      Message To Cross Posters

      Comment

      Working...
      X