How to Reset filter before saving a worksheet using VBA in Excel?
Tags: toresetfilterbefores, vbamacros
Published: 2021-09-28 11:40:21

---
title: How to Reset filter before saving a worksheet using VBA in Excel?
published: true
date: 2021-09-24 09:59:09 UTC
tags: ToResetFilterBeforeS,VBAMacros
canonical_url: https://geekexcel.com/how-to-reset-filter-before-saving-a-worksheet-using-vba-in-excel/
---

In this post, we will explain to you how to  **reset the filter before saving a worksheet** using VBA in Excel. Let’s see them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, in the  **VBAProject pane** , you have to  **double-click ThisWorkbook**.
- After that, you need to  **copy and paste the code**  given below.

```
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,Cancel As Boolean)
   Dim wks As Worksheet
   For Each wks In Worksheets
      If wks.FilterMode = True Then
         wks.ShowAllData
      End If
   Next wks
End Sub

```

- You have to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-79-1024x291.png)<figcaption>Save the Code</figcaption>

- Again, you need to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You have to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you need to make sure that your  **macro name is selected**  and click the  **Run ** button.
- Finally, you will get the **output** as the **resetting the filter** before saving a worksheet in **Excel**.

## Verdict

We hope that this tutorial gives you guidelines on how to  **reset the filter before saving a worksheet** using VBA in Excel. Please leave a comment in case of any **queries,** and don’t forget to mention your valuable **suggestions** as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Related Articles:**

- **[How to update data from one sheet to Another Sheet through VBA in Microsoft Excel?](https://geekexcel.com/how-to-update-data-from-one-sheet-to-another-sheet-through-vba-in-microsoft-excel/)**
- **[Merge Tables By Matching Column From Two Worksheets in Excel](https://geekexcel.com/how-to-update-merge-tables-by-matching-column-from-two-worksheets-workbooks-in-excel/)**
- **[How to Enter Today’s Date With Time in Excel? Using Shortcuts!!](https://geekexcel.com/enter-todays-date-with-time-excel/)**
- **[Enter the Date in Excel Sheet ~ Step-by-Step Procedure!!](https://geekexcel.com/enter-the-date-excel/)**
- **[How to Add an Input Message in Data Validation in Excel office 365?](https://geekexcel.com/how-to-add-an-input-message-in-data-validation-in-excel-office-365/)**