Link to home
Start Free TrialLog in
Avatar of Mighty1072
Mighty1072Flag for United States of America

asked on

Auto Filter Macro Help - Rewrite code

I have a code below that remove auto filter. But I wrote the code incorrectly.

Please help rewrite it. The purpose of the code is: if the sheet has auto filter then turn it off.

THanks,
Sub FilterOff()

    'XXXXX Turn off auto filter XXXXXXXXXX
    Dim ws As Worksheet
  ws = ActiveWorkbook.Worksheets
  If ws.Worksheets.AutoFilterMode Then Selection.AutoFilter
    'xXXX Turn off auto filter XXXXXXXXXXXXXXXX

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mighty1072,

For all sheets it would be more like:

chris_bottomley
Sub FilterOff()
Dim ws As Worksheet

    'XXXXX Turn off auto filter XXXXXXXXXX
    For Each ws In ThisWorkbook.Worksheets
        If ws.AutoFilterMode Then Selection.AutoFilter
    Next
    'xXXX Turn off auto filter XXXXXXXXXXXXXXXX

End Sub

Open in new window

Avatar of Mighty1072

ASKER

work great!!!! Thanks,
Glad to help

Chris