Tested in Excel 365 (16.8730.2046) 64-bit
- Public Sub AutoFilterOrUnfilter()
- If ActiveSheet.AutoFilterMode Then ' if autofilter is on
- If ActiveSheet.FilterMode = True Then 'if the data is filtered
- ActiveSheet.ShowAllData ' remove the filter to show all data
- End If
- Else
- Cells.Select ' select all sheet
- Selection.AutoFilter ' add autofilter
- End If
- End Sub