Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to clear filters when opening, saving or closing workbook in Excel?

Supposing there are multiple filtered worksheets in your workbook, for clearing these filters, you have to check for the filtered list in different worksheets and then manually clear them one by one. That’s annoying! In this article, we will show you methods of clearing filters when opening, saving or closing a workbook in Excel.

Clear filters when opening workbook in Excel

Clear filters when saving workbook in Excel

Clear filters when closing/exiting workbook in Excel


arrow blue right bubble Clear filters when opening workbook in Excel


This section is talking about clearing filters in all worksheets when opening a workbook. Please do as follows.

1. In a workbook you need to automatically clear all filters when opening, please press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, please double click ThisWorkbook in the left Project pane, and then copy and paste the below VBA code into the ThisWorkbook (Code) window. See screenshot:

VBA code: Clear all filters when opening workbook

Private Sub Workbook_Open()
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.AutoFilterMode Then
            ws.AutoFilterMode = False
        End If
    Next ws
End Sub

3. Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.

4. Click File > Save As. In the popping up Save As dialog box, specify a folder to save this workbook, name it as you need in the File name box, then select Excel Macro-Enabled Workbook option from the Save as type drop-down list, and finally click the Save button.

From now on, when opening this Macro-Enabled Workbook, all filters in this workbook will be cleared automatically.


arrow blue right bubble Clear filters when saving workbook in Excel

You can clear all filters from current workbook each time you saving it.

1. In the workbook you need to automatically clear all filters from, please press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, please double click ThisWorkbook in the left Project pane, and then copy and paste the below VBA code into the ThisWorkbook (Code) window. See screenshot:

VBA code: Clear filters when saving workbook

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.AutoFilterMode Then
            ws.AutoFilterMode = False
        End If
    Next ws
End Sub

3. Press Alt + Q keys to exit the Microsoft Visual Basic for Applications window.

From now on, when saving the workbook, all filters will be cleared automatically.


arrow blue right bubble Clear filters when closing/exiting workbook in Excel

The last section, we will show you how to clear all filters across worksheets when closing or exiting the workbook.

1. Open the workbook you need to automatically clear all filters from, then press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, please double click ThisWorkbook in the left Project pane, and then copy and paste the below VBA code into the ThisWorkbook (Code) window. See screenshot:

VBA code: Clear all filters across worksheets when closing/exiting workbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.AutoFilterMode Then
            ws.AutoFilterMode = False
        End If
    Next ws
End Sub

Note: If you just want to clear filters in current worksheet, please use the below VBA code.

VBA code: Clear filter in active sheet when closing workbook

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If ActiveSheet.AutoFilterMode Then
        ActiveSheet.AutoFilterMode = False
    End If
End Sub

3. Press Alt + Q keys to exit the Microsoft Visual Basic for Applications window.

From now on, all filters will be cleared automatically after clicking the Close button in the workbook.


arrow blue right bubbleRelated articles:


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Bryan · 1 years ago
    This solution doesn't "clear" the AutoFilters, it removes them completely.
    To reset the filters and retain them for the next session, substitute ws.AutoFilter.ShowAllData for ws.AutoFilterMode = False
    • To post as a guest, your comment is unpublished.
      Paul · 7 months ago
      Thank you for this comment! This is exactly what I needed for my spreadsheet. Much appreciated!