Erase filter with macro button

  • Thread starter Thread starter bren
  • Start date Start date
B

bren

Hi,

I have this code

Sub select()

Selection.AutoFilter Field:=3, Criteria1:="X"
End Sub

The idea is to assign it to a button and when clicking it filters all
x values, and if I click again on this button it deletes the filter. I
don´t know how to do this second step.

THANKS
 
One way
Sub ToggleFilter()
Set sn = Sheets("sheet7")
With sn.Range("a1:c21")
If sn.FilterMode = False Then
.AutoFilter Field:=3, Criteria1:="X"
Else
.AutoFilter
End If
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Hi,

I have this code

Sub select()

Selection.AutoFilter Field:=3, Criteria1:="X"
End Sub

The idea is to assign it to a button and when clicking it filters all
x values, and if I click again on this button it deletes the filter. I
don´t know how to do this second step.

THANKS
 
Back
Top