Excel 2013 VBA Clear All Filters macro

后端 未结 26 993
花落未央
花落未央 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:04

    Try something like this:

    Sub ClearDataFilters()
    'Clears filters on the activesheet. Will not clear filters if the sheet is protected.
    On Error GoTo Protection
    If ActiveWorkbook.ActiveSheet.FilterMode Or _
       ActiveWorkbook.ActiveSheet.AutoFilterMode Then _
       ActiveWorkbook.ActiveSheet.ShowAllData
    
    Exit Sub
    Protection:
    If Err.Number = 1004 And Err.Description = _ 
        "ShowAllData method of Worksheet class failed" Then
        MsgBox "Unable to Clear Filters. This could be due to protection on the sheet.", _
        vbInformation
    End If
    
    End Sub
    

    .FilterMode returns true if the worksheet is in filter mode. (See this for more information.)
    See this for more information on .AutoFilter.
    And finally, this will provide more information about the .ShowAllData method.

提交回复
热议问题