Excel filters can be handy, but when you want to remove them across every sheet—especially after automation or manual filtering—doing it manually is tedious. The simplest way is to use VBA to clear all filters on all sheets at once, saving hours of repetitive work. This method works for Excel 2016, 2019, 365, and older versions (with minor adjustments). No extra plugins are needed—just a quick macro.
What You'll Need
- A blank or open Excel workbook (no data loss from clearing filters).
- Microsoft Excel installed (VBA editor must be enabled).
- A text editor (like Notepad) to write the macro code.
Step-by-Step
- Enable VBA Editor: Open Excel, go to File > Options > Customize Ribbon. Check the box for "Developer" under "Main Tabs," then click OK. Excel will ask to restart—do so.
- Write the Macro Code:
In the Excel ribbon, click Developer > Visual Basic (or press Alt+F11). This opens the VBA editor. In the Project Explorer, double-click the workbook tab (e.g., "ThisWorkbook") to insert a new module. Paste this code:
Sub ClearAllFilters() Dim ws As Worksheet On Error Resume Next ' Skip sheets without filters or errors For Each ws In ThisWorkbook.Worksheets ws.ListObjects(0).Range.AutoFilter Field:=0 ' Field 0 = first column ws.ListObjects(0).Range.AutoFilter Field:=0, Criteria1:="*" ' Reset filter to all values Next ws On Error GoTo 0 End SubSave the file with a *.xlsm extension (macro-enabled). - Test the Macro: Close the VBA editor. Go back to Excel and run the macro by pressing Alt+F8, selecting ClearAllFilters, and clicking Run. Verify each sheet’s filters disappear.
- Run Automatically: If you use this often, place the macro in a Quick Access Toolbar or create a shortcut: Go to Developer > Macros, select ClearAllFilters, and click Run (or assign a keyboard shortcut).
Common Mistakes
- Error Handling Skipped: If you omit `On Error Resume Next`, the macro will freeze if a sheet lacks filters or has errors (e.g., empty data ranges). The code above prevents this by masking errors gracefully.
- Excel Version Differences: In older Excel versions (pre-2010), replace `ListObjects(0).Range.AutoFilter` with `Range.AutoFilter`. This skips structured tables.
- Filter Fields Without Criteria:
If your sheet uses filters on multiple columns (e.g., columns A–D), change the code to loop through fields:
For Each ws In ThisWorkbook.Worksheets ws.ListObjects(0).Range.AutoFilter For i = 1 To ws.ListObjects(0).Range.Columns.Count ws.ListObjects(0).Range.AutoFilter Field:=i, Criteria1:="*" Next i Next ws
Tips
- Backup Data: Always save a backup before running macros on critical workbooks. Use File > Save As > Copy to duplicate the file.
- Debugging: If filters reappear, check for hardcoded filter ranges (e.g., `worksheet.Range("A1:D100").AutoFilter`). Disable them manually before automating.
- Performance:
For large workbooks (>10,000 rows/sheets), add a delay between sheets:
Application.Wait Now + TimeValue("0:00:01") - Conditional Filtering:
If your filters rely on formulas (e.g., criteria derived from cells), clear formulas first:
ws.Range.AutoFormat (xlAutoFormatNone)
Troubleshooting
If the macro fails, try these steps in order:
- Check Workbook Type: If the file is saved as .xlsx, VBA may not work. Ensure the file is .xlsm (macro-enabled).
- Verify Sheet Names:
Open the macro’s location in the VBA editor:
ThisWorkbook.Worksheets("Sheet1").AutoFilterEnsure no sheets with typos exist. Rename problematic sheets or skip them by editing the loop. - Test in a Blank Workbook: Run the macro on a fresh workbook. If it works, the issue is in your original file (e.g., nested filters or hidden sheets).
- Enable Debugging: Press F8 after running the macro to step through errors. Look for `Range.AutoFilter` errors—these often mean the sheet lacks data or has no filters.
- Update Excel: Older Excel versions may lack compatibility with newer VBA syntax. Update Excel to the latest version (2016+ recommended).
Frequently Asked Questions
Will this macro clear filters on all sheets, including hidden ones?
Yes, but hidden sheets may cause errors. To skip hidden sheets, modify the loop to check `Visible = True`:
For Each ws In ThisWorkbook.Worksheets
If ws.Visible = xlSheetVisible Then
ws.ListObjects(0).Range.AutoFilter Field:=0, Criteria1:="*"
End If
Next ws
How can I clear filters only on specific sheets?
Replace the loop with named sheets:
Sub ClearFiltersOnSheets()
Sheets("Sheet1").ListObjects(0).Range.AutoFilter Field:=0, Criteria1:="*"
Sheets("Sheet2").ListObjects(0).Range.AutoFilter Field:=0, Criteria1:="*"
End Sub
Why do filters reappear after running the macro?
Possible causes: 1. Manual filters added via Data > Filter later. 2. Data changes triggering automatic filters (e.g., pivot tables). 3. A VBA macro explicitly setting filters. Check Developer > Macros for conflicting macros.
Does this work for pivot tables?
No. Pivot tables use their own filter controls. Clear them manually via the PivotTable Tools > Design > Filters menu.
How do I undo the macro’s effect?
There’s no direct undo, but reset filters manually for each sheet or re-run the macro (it’s idempotent). For large files, export data as CSV to avoid resetting.
Can I apply this to Excel Online or Web?
No. VBA only works in installed Excel (Windows/macOS). For web versions, use browser extensions or Power Query to clear filters.