Consulting

Results 1 to 3 of 3

Thread: How do you clear filter in macro?

  1. #1

    How do you clear filter in macro?

    I'm just wondering, how will you clear filter in macro?

    My original code is:
    Sub FilterB6()
        Dim fld
        Application.ScreenUpdating = False
        If UCase(Range("B5").Value) <> "ALL" Then
            Range("A5:AA5").AutoFilter Field:=2, Criteria1:=Range("A3"), visibledropdown:=False
            With ActiveSheet.AutoFilter
                For fld = 1 To 27
                    If Not .Filters(fld).On Then
                        Range("A5:AA5").AutoFilter Field:=fld, visibledropdown:=False
                    End If
                Next fld
            End With
        Else
            If ActiveSheet.AutoFilterMode Then
                Range("A5:AA5").AutoFilter
            End If
        End If
        Application.ScreenUpdating = True
        Range("A1").Select
    End Sub
    I want to create another code that will clear the filter

    Thanks!!!

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You already have it in your code, autofilter in vba is a toggle thing, this will enable it:
    Range("A5:AA5").AutoFilter
    and running this again will disable it:
    Range("A5:AA5").AutoFilter
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Thanks Simon!

Posting Permissions

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