Jim wants a way to quickly tell what filtering criteria have been applied in an AutoFilter. He has a hard time telling even which columns have filtering applied (the slight change in drop-down arrow color from black to blue is hardly noticeable), so some other method of telling where a filter is applied would be nice.
The lack of contrast between the black and blue drop-down arrows in a filtered column is not an uncommon complaint. In fact, this very issue was addressed in a different issue of ExcelTips. (You can search at the ExcelTips Web site for the phrase "drop-down arrow colors" for a handy tip in this regard.)
If you actually want to know what criteria are being applied to a column, then you'll be interested in a small macro that will place the criteria into another cell:
Function DispCriteria(Rng As Range) As String Dim Filter As String Filter = "" On Error GoTo Done With Rng.Parent.AutoFilter If Intersect(Rng, .Range) Is Nothing Then GoTo Done With .Filters(Rng.Column - .Range.Column + 1) If Not .On Then GoTo Done Filter = .Criteria1 Select Case .Operator Case xlAnd Filter = Filter & " AND " & .Criteria2 Case xlOr Filter = Filter & " OR " & .Criteria2 End Select End With End With Done: DispCriteria = Filter End Function
This is actually a user-defined function that you can use in your worksheet. For instance, if you wanted to know the filtering criteria that was applied to column C, you could use the following in a cell:
=DispCriteria(C:C)
If you prefer, you could simply reference the header cell for the column being filtered. For example, if the header (the one to which AutoFilter adds the drop-down arrow) is cell C3, you could use the following:
=DispCriteria(C3)
The criteria displayed by the function are those actually used by AutoFilter. For instance, if you use a filtering criteria that says "Top 10," then Excel translates that at the time it is applied into something like ">=214.3281932" (the value will vary, depending on your data). It is the formulatic filter that is returned by the DispCriteria function, not the "Top 10" wording.
The function is based on one created by Microsoft MVP Stephen Bullen. The macro has been published in various places, and you can find it on John Walkenbach's Web site, here:
http://www.j-walk.com/ss/excel/usertips/tip044.htm
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2891) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
The drop-down arrow used at the top of columns by AutoFilter can be difficult to see. Here's a way you can reduce the ...
Discover MoreThe filtering capabilities of Excel are very helpful when you are working with large sets of data. You can create a ...
Discover MoreIf you have a large number of data records, each with an associated date, you might want to filter that data so you see ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-09-09 09:41:29
Joanna Weir
using the above code, when I filter using "Text filter Contains" and type a partial search (e.g. 'Whole' instead of 'Wholesale'.... the filter works, but the formula to display the filter criteria is blank. Please advise how to resolve this.
2019-09-03 16:38:28
Mark
Hi Allen,
This works great when using the formula bar where there is only 2 criteria active. However is the auto filter has more than 2 criteria this only displays a blank cell. How can this be upgraded to list all possible criteria? I have tried to adjust this so I can call this function from inside another function but it doesn't work. Do you know how to adjust this so it can be exclusive to the vba environment?
Thank you
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2022 Sharon Parq Associates, Inc.
Comments