by Allen Wyatt
(last updated February 19, 2018)
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:
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.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
The advanced filtering capabilities of Excel allow you to easily perform comparisons and calculations while doing the ...Discover More
Using the fill handle is a great way to quickly fill a range of cells with values. Sometimes, however, the way to fill ...Discover More
The filtering feature in Excel allows you to quickly copy unique information from one data list to another. If you want ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.