Using a Filtered Value in a Formula

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.

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

Exporting a Graphics Group

Need to export a graphics group from a chart so that you can use the group in a different program? It's not as easy as ...

Discover More

Combining Worksheets from Many Workbooks

Do you need to pull a particular worksheet out of a group of workbooks and combine those worksheets into a different ...

Discover More

Tombstone Date Math

Doing math with dates is easy in Excel. Doing math with old dates, such as those you routinely encounter in genealogy, is ...

Discover More

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!

More ExcelTips (ribbon)

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

Copying Comments when Filtering

The filtering feature in Excel allows you to quickly copy unique information from one data list to another. If you want ...

Discover More

Filtering Columns

The filtering tools provided in Excel make it easy to filter a data list so that only certain rows are displayed. What if ...

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 nine more than 4?

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.