Excel 2013 VBA Clear All Filters macro

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

    Here is some code for fixing filters. For example, if you turn on filters in your sheet, then you add a column, then you want the new column to also be covered by a filter.

    Private Sub AddOrFixFilters()
    
        ActiveSheet.UsedRange.Select
    
        ' turn off filters if on, which forces a reset in case some columns weren't covered by the filter
        If ActiveSheet.AutoFilterMode Then
            Selection.AutoFilter
        End If
    
        ' turn filters back on, auto-calculating the new columns to filter
        Selection.AutoFilter
    
    End Sub
    

提交回复
热议问题