Table of Contents
VBA, or Visual Basic for Applications, is a programming language commonly used to automate tasks in Microsoft Excel. One useful function of VBA is the ability to clear all filters in an Excel worksheet. This means that all applied filters will be removed, allowing the user to view the entire dataset without any filters in place. To do this, one can use the “AutoFilter” method in VBA, which allows for the clearing of all filters in a specific range or table. This can be done by writing a simple VBA code, which can then be executed to clear all filters in the desired worksheet. This function can significantly improve efficiency and accuracy when working with large datasets in Excel.
Clear Filters in Excel Using VBA (With Example)
You can use the following syntax in VBA to clear all filters from an Excel sheet:
Sub ClearFilters()
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
End Sub
This particular macro will clear all filters on the sheet that is currently active.
This macro works by using the ShowAllData method to force all rows that are currently hidden to be visible.
If there are not any rows currently being filtered on the active sheet, then nothing will happen when you run this macro.
The following example shows how to use this macro in practice.
Example: Clear All Filters in Excel Using VBA
Suppose we have the following dataset in Excel that contains information about various basketball players:

Now suppose we add a filter to only display the rows where the value in the Team column is equal to Mavs or Nets:

Now suppose that we would like to clear this filter using VBA.
We can create the following macro to do so:
Sub ClearFilters()
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
End SubWhen we run this macro, the filter will automatically be cleared from the sheet:

Notice that all of the rows that were previously hidden are now visible again because we cleared the filter.
Cite this article
stats writer (2024). How can I use VBA to clear all filters in Excel?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-clear-all-filters-in-excel/
stats writer. "How can I use VBA to clear all filters in Excel?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-clear-all-filters-in-excel/.
stats writer. "How can I use VBA to clear all filters in Excel?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-clear-all-filters-in-excel/.
stats writer (2024) 'How can I use VBA to clear all filters in Excel?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-clear-all-filters-in-excel/.
[1] stats writer, "How can I use VBA to clear all filters in Excel?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to clear all filters in Excel?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
