PDA

View Full Version : [SOLVED] How do you clear filter in macro?



genracela
07-21-2010, 11:49 PM
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!!!

Simon Lloyd
07-22-2010, 12:04 AM
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

genracela
07-22-2010, 10:46 PM
Thanks Simon!