Excel 2013 VBA Clear All Filters macro

后端 未结 26 954
花落未央
花落未央 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 16:53

    This will first check if AutoFilterMode is set (filtering is possible), then check if FilterMode is on (you are filtering on something) then turn off filtering.

    Regarding Errors, i.e. protection - se other answers

    Context added (my script is looping over sheets, which are then saved as CSV, hence the need to remove filters - but keep AutoFilterMode on, if set:

    For Each WS In ActiveWorkbook.Worksheets
      Select Case WS.Name
        Case "01", "02", "03", "04", "05"
          With WS
            If WS.AutoFilterMode Then
                If WS.FilterMode Then WS.ShowAllData
            End If
    
            ' Processing data
          End With
        Case Else
          ' Nothing to see here
      End Select
    Next
    

提交回复
热议问题