Excel 2013 VBA Clear All Filters macro

后端 未结 26 854
花落未央
花落未央 2020-11-27 16:26

It seems older macros are not working. I have proper securtiy set to run VBA macros but when I have tried a few methods for clearing ALL filters on a worksheet, I get a comp

相关标签:
26条回答
  • 2020-11-27 17:14

    Try this:

    If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
    
    0 讨论(0)
  • 2020-11-27 17:14

    This will clear only if you have filter and does not cause any error when there arent any filter. If ActiveSheet.AutoFilterMode Then ActiveSheet.Columns("A").AutoFilter

    0 讨论(0)
  • 2020-11-27 17:14

    I am using this approach for a multi table and range sheet as a unique way.

    Sub RemoveFilters(Ws As Worksheet)
    Dim LO As ListObject
    On Error Resume Next
        Ws.ShowAllData
        For Each LO In Ws.ListObjects
            LO.ShowAutoFilter = True
            LO.AutoFilter.ShowAllData
        Next
        Ws.ShowAllData
    End Sub
    
    0 讨论(0)
  • 2020-11-27 17:14

    You must select range of the table first before using ActiveSheet.ShowAllData

    0 讨论(0)
  • 2020-11-27 17:15

    All you need is:

        ActiveSheet.AutoFilter.ShowAllData
    

    Why? Like the worksheet, AutoFilter also has a ShowAllData method, but it doesn't throw an error even when auto filter is enabled without an active filter.

    0 讨论(0)
  • 2020-11-27 17:18

    Loop AutoFilter columns, if column is activated(on) then reset a column filter, you may insert a new criteria after a loop. This code does not remove AutoFilter banner.

    Dim iCol as Long
    Dim ws as Worksheet
    ...
    For iCol = 1 To ws.AutoFilter.Filters.count
      If ws.AutoFilter.Filters(iCol).On Then ws.AutoFilter.Range.AutoFilter Field:=iCol
    Next
    ...
    ws.AutoFilter.Range.AutoFilter Field:=4, Criteria1:="AABBCC"
    
    0 讨论(0)
提交回复
热议问题