Filter: Macro/CommandButton - Show filtered data-Show all

  • Thread starter Thread starter Snoopy
  • Start date Start date
S

Snoopy

Hey Guys

I intend my macro to do this:
If autofilter is activated then show all, if not then activate
autofilter .

- a kind of on/off autofiler-button based on some "spagetti"-
programming of mine:

Selection.AutoFilter Field:=7, Criteria1:="MTO OK"
ActiveSheet.ShowAllData

.... but I struggle to make this work, and humberly ask you guys for
help.

Best Regards
Snoopy
 
With Worksheets("sheet1")
If .FilterMode Then
.ShowAllData
else
Selection.AutoFilter Field:=7, Criteria1:="MTO OK"
End If
End With

But I really don't like using the current selection.

Maybe...
..range("a1").currentregion.AutoFilter Field:=7, Criteria1:="MTO OK"

would be safer.
 
Back
Top