To remove an AutoFilter in Excel VBA, use ActiveSheet.AutoFilterMode = False to clear the filter dropdowns and restore all hidden rows on the active sheet. If you only want to clear the filter criteria but keep the dropdown arrows, use ActiveSheet.ShowAllData instead. That one-line answer covers most cases; the rest of this guide explains when to use each method, how to target a specific worksheet or table, and what to do when the code errors out.

What You'll Need

  • Excel with macros enabled (the Developer tab visible, or the ability to open the VBA Editor with Alt+F11).
  • A workbook that contains at least one AutoFilter, or a willingness to add one for testing.
  • Basic familiarity with running a macro: either the Macro dialog (Alt+F8) or the Immediate Window in the VBA Editor.
  • Macro security set to allow macros in the file you are working on. If macros are blocked, the code will not run at all.

Step-by-Step

  1. Open the VBA Editor. Press Alt+F11 (on Mac, Fn+Alt+F11 or the Developer tab > Visual Basic). The editor opens in a separate window.
  2. Insert a module. In the editor, choose Insert > Module. A blank code window appears. Keeping the code in a standard module makes it easy to run from the Macro dialog.
  3. Write the basic removal line. Type Sub RemoveFilter(), press Enter, then type ActiveSheet.AutoFilterMode = False, then End Sub. This removes the filter dropdowns entirely from the active sheet and unhides every row.
  4. Run the macro. Press F5 while the cursor is inside the subroutine, or close the editor and use Developer > Macros (Alt+F8), select RemoveFilter and click Run. The filter arrows disappear and all rows are visible.
  5. Target a specific sheet instead of the active one. Replace ActiveSheet with a worksheet reference, for example Worksheets("Data").AutoFilterMode = False. Using the sheet name avoids removing a filter from the wrong sheet when the user has clicked elsewhere.
  6. Clear criteria only, keeping the dropdowns. If you want the arrows to stay but all rows shown, use ActiveSheet.ShowAllData. Wrap it in error handling because it raises an error when no filter is currently applied: On Error Resume Next before the line and On Error GoTo 0 after it.
  7. Remove a filter from a ListObject (Excel Table). For a table named SalesTable, use ActiveSheet.ListObjects("SalesTable").AutoFilter.ShowAllData to clear criteria, or set ActiveSheet.ListObjects("SalesTable").Range.AutoFilter off by clearing the filter field. Tables always keep their filter buttons, so AutoFilterMode does not apply to them.
  8. Loop through every sheet in the workbook. Use Dim ws As Worksheet, then For Each ws In ThisWorkbook.Worksheets, inside the loop test If ws.AutoFilterMode Then ws.AutoFilterMode = False, and close with Next ws. The test prevents errors on sheets that have no filter.
  9. Save the workbook as macro-enabled. Use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm). A plain .xlsx file discards the VBA code when saved.

Menu labels and dialog wording can differ slightly between Excel versions and between Windows and Mac. The VBA keywords above are the same across versions.

Common Mistakes

Using ShowAllData on a sheet with no filter. This throws run-time error 1004. Always guard it with a check such as If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData, or use error handling.

Confusing AutoFilterMode with FilterMode. AutoFilterMode tells you whether the dropdown arrows exist on the sheet. FilterMode tells you whether any rows are currently hidden by a filter. Setting AutoFilterMode to False removes the arrows; it is not the same as clearing criteria.

Running the macro on the wrong sheet. ActiveSheet depends on what the user last clicked. In shared or automated workbooks, reference sheets by name or by index so the code is predictable.

Assuming tables behave like ranges. An Excel Table keeps its filter buttons permanently. You cannot remove them with AutoFilterMode; you can only clear the criteria with ShowAllData on the ListObject.

Forgetting to disable events or screen updating in long loops. When looping many sheets, wrap the loop with Application.ScreenUpdating = False and restore it to True at the end. Otherwise the screen flickers and the macro runs slowly.

Saving as .xlsx. The code disappears on save. Use .xlsm or .xlsb.

Tips

Put the removal code in a Workbook_Open event if you want every filter cleared whenever the file is opened. That keeps reports in a consistent state for the next user.

Combine removal with a reset of the used range: after clearing the filter, you can also reset the scroll area or select cell A1 so the user lands at the top of the data.

Name your macro something descriptive like ClearAllFilters rather than Macro1, so it is easy to find in the Macro dialog.

If you record a macro while removing a filter manually, Excel writes the exact lines for your version. Recording is a safe way to confirm the syntax before you edit it.

Test on a copy of the workbook first. Removing filters changes what users see, and an accidental run on a protected sheet will raise an error unless the sheet is unprotected first.

Troubleshooting

Run-time error 1004. Usually caused by calling ShowAllData when no filter is applied, or by trying to change a protected sheet. Check FilterMode first, and unprotect the sheet with the correct password before changing filters.

Nothing happens when the macro runs. Confirm the code is in a standard module, not a sheet module, and that macros are enabled. Also check that the active sheet actually has a filter; AutoFilterMode = False on a sheet without one does nothing and raises no error.

The arrows disappear but rows stay hidden. That can happen if rows were hidden manually rather than by a filter. AutoFilter removal does not unhide manually hidden rows. Select the rows and use Format > Row > Unhide.

Error on a table. Use the ListObject approach described in step 7 rather than AutoFilterMode. If the table name is wrong, Excel raises an error; check the name in Table Design.

Macro blocked by security. Enable macros for the file location, or move the workbook to a trusted location. Do not lower security settings globally just to run one file.

Frequently Asked Questions

What is the difference between AutoFilterMode and ShowAllData?

AutoFilterMode = False removes the filter dropdown arrows from the sheet. ShowAllData keeps the arrows but clears the criteria so every row is visible. Use the first to remove filtering entirely, the second to reset it.

Can I remove filters from all sheets at once?

Yes. Loop through ThisWorkbook.Worksheets and set AutoFilterMode = False on each sheet that has it enabled. Test with the AutoFilterMode property before changing it to avoid errors.

Why does ShowAllData give me an error?

It errors when the sheet has no filter currently applied. Check the FilterMode property first, or wrap the call in On Error Resume Next and reset error handling afterward.

Does this work on Excel Tables?

Tables keep their filter buttons by design, so AutoFilterMode does not remove them. You can clear the criteria with the ListObject's AutoFilter.ShowAllData method.

Will removing a filter unhide rows hidden manually?

No. Removing an AutoFilter only restores rows hidden by the filter. Rows hidden manually stay hidden until you unhide them yourself.

Do I need to save as .xlsm?

Yes. A standard .xlsx workbook cannot store VBA code. Save as Excel Macro-Enabled Workbook (.xlsm) or Excel Binary Workbook (.xlsb) to keep the macro.