Excel 2013 VBA Clear All Filters macro

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

    Wow. Logging in afterwards deleted all but a portion of the first line. My mistake. However, this will be terse.

    For both tests Enter text in A1 and A5 of Sheet1 Filter for blanks only. Run either test Enter text in A5 Try to filter!

    Sub SubsequentFilterFails()
       With Sheet1     'assumes code name is still Sheet1
          .ShowAllData  'assumes a filter has been applied
          .Range(.Cells(2, 1), .Cells(7, 1)).EntireRow.Delete
       End With
    End Sub
    
    Sub SubsequentFilterWorks()
       With Sheet1
          .Cells.AutoFilter
          .Range(.Cells(2, 1), .Cells(7, 1)).EntireRow.Delete
          .Cells.AutoFilter
       End With
    End Sub
    

    Thus, when filters are being cleared in order to clean the worksheet .Cells.AutoFilter will be used.

提交回复
热议问题