Clearing Only Filtering Settings

Written by Allen Wyatt (last updated October 15, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


On many of his worksheets, Roy uses sorting and filtering extensively. On the Data tab of the ribbon, in the Sort & Filter group, there is a Clear tool. This tool clears all filtering and sorting settings. Roy routinely needs to clear the filtering settings, but he would like his sorting settings to remain unaffected by the clearing. He wonders if there is a way to either change how this tool behaves or to clear only the filtering settings in a single action.

This was an interesting problem to research, and it took a bit of poking and prodding. It appears that Excel allows you to define sorting settings for the filters you apply to a data set. To see this in action, follow these steps:

  1. Open a workbook that has some data in it, or create a workbook that has data you can sort and filter.
  2. Select a cell within the data.
  3. Display the Data tab of the ribbon.
  4. Click the Filter tool, within the Sort & Filter group. Excel places drop-down arrows at the top of each column in your data.
  5. Click the drop-down arrow at the top of one of the column.

Note that the drop-down menu that appears allows you to select which data is filtered in the column. This is where people normally stop looking, though. It is interesting that at the top of the drop-down menu there are some sorting controls. If you use these controls, then the filtered results that Excel displays are filtered according to your specifications.

If you turn on the macro recorder at this point (after applying a filter that includes sorting) and click the Clear tool, this is the macro that is recorded by Excel:

Sub Macro1()
'
' Macro1 Macro
'

'
    ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
    ActiveSheet.ShowAllData
End Sub

Note that there are two lines in the recorded macro. The first line clears the sorting settings and the second clears all the filtering settings. If you record the same steps without having first chosen a sorting setting in the drop-down filtering menu at the top of a column, then Excel doesn't include the first line.

The upshot of this is that you can easily create your own single-line macro that removes any filtering but retains any sorting settings made through the filtering drop-down. The simple macro would look like this:

Sub ClearFilter()
    ActiveSheet.ShowAllData
End Sub

It should be noted that if you turn off filtering (by clicking a second time on the Filter tool), Excel automatically clears any filtering and sorting settings you may have applied. If you want to retain sorting settings—particularly complex sorting settings—outside of the filtering framework, then it would be best to record a macro of the steps you go through for sorting your data.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12254) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting the Total Number of Pages in Your Document

Word keeps track of many statistics for each of your documents. One statistic is the total number of pages in the printed ...

Discover More

Deleting Worksheet Code in a Macro

When creating an application in VBA for others to use, you might want a way for your VBA code to modify or delete other ...

Discover More

Turning Off the Check for Repeated Words

If your work involves the usage of repeated words, you may be interested in configuring Word so it doesn't flag those ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Enabling Filters by Default

Filtering can be a powerful way to work with large amounts of data in a worksheet. If you use filtering quite a bit, you ...

Discover More

Finding Rows with Values in Two Columns

When you use Excel to input and store information, you need to be concerned with whether the information meets your ...

Discover More

Non-PivotTable Slicers and Timelines

When working with a PivotTable, slicers and timelines can make short work of large data sets. This tip looks at all the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.