Written by Allen Wyatt (last updated December 26, 2022)
This tip applies to Excel 2007, 2010, and 2013
Chuck has a worksheet with 16 columns and 622 rows. When he filters on one column to display only those rows that contain a particular value, he would like to change the heading (contained in cell A1) so that it contains whatever value he filtered on. Thus, if Chuck filtered so that only cell values containing the word "Central" are displayed, he wants the heading to change to "Accounts Belonging to Central." He wonders how to grab the value by which he's filtering and then use that value in the formula that is used for the heading.
Excel provides two different ways you can filter your data. You can either use regular filtering (what used to be called AutoFiltering) or you can use advanced filtering. If you are using advanced filtering, then accomplishing what you want is somewhat easier because the criteria are stored in cells, in a criteria table. (I won't go into how to set up an advanced filter here; you can search for it on the ExcelTips site—just use the search box at the upper-right of any page.)
Since the criteria are stored in cells, you can use a formula to put together your heading based on the contents of those cells. Where you'll run into issues is if you specify multiple filtering criteria, which can make the heading formula trickier.
If you are using regular filtering—which it seems like Chuck is probably doing—then the filter specification is not stored in a cell; it is maintained internally by Excel. That makes accessing the information more difficult. Fortunately, it can be extracted with a macro, and someone has already done the "heavy lifting" for Excel users before. (No sense in reinventing the wheel, so to speak.) You can find macros that return filtering criteria at these two locations:
http://j-walk.com/ss/excel/usertips/tip044.htm http://www.ozgrid.com/VBA/autofilter-criteria.htm
The relatively short routines at either site are set up as user-defined functions, allowing you to specify a cell whose criteria you want to return. Thus, if Chuck applied the "Central" filter to the cells in column C (where the actual filter is in cell C3 for all cells below that), then the heading could be constructed in this way:
="Accounts Belonging to " & FilterCriteria(C3)
This formula relies on the function detailed at the j-walk site; if you used the one at the OzGrid site you'd have to change the formula to reflect the function name defined there. You test the two functions at the two sites to discover which one works best for your needs and your data.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12839) applies to Microsoft Excel 2007, 2010, and 2013.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
When you use Excel to input and store information, you need to be concerned with whether the information meets your ...
Discover MoreThe filtering feature in Excel allows you to quickly copy unique information from one data list to another. If you want ...
Discover MoreThe filtering tools provided in Excel make it easy to filter a data list so that only certain rows are displayed. What if ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments