Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Returning Item Codes Instead of Item Names.
by Allen Wyatt
(last updated June 17, 2017)
Alan can use data validation to create a drop-down list of valid choices for a cell. However, what he actually needs is more complex. He has a large number of item names with associated item codes. In cell B2 he can create a data validation list that shows all the item names (agitator, motor, pump, tank, etc.). The user can then choose one of these. When he references cell B2 elsewhere, however, he wants the item code—not the item name—returned by the reference. Thus, the reference would return A, M, P, TK, etc. instead of agitator, motor, pump, tank, etc.
There is no direct way to do this in Excel. The reason is because data validation lists are set up to include only a single-dimensional list of items. This makes it easy for the list to contain your item names. However, you can expand how you use the data validation list a bit to get what you want. Follow these steps:
Figure 1. The New Name dialog box.
Figure 2. The Data Validation dialog box.
With these steps done, people can still use the data validation drop-down list to select valid item names. What you now need to do is reference the item code from the data table you set up in step 1. You can do that with a formula such as this:
This formula can be used on its own (to put the desired item code into a cell) or it could be used within a larger formula, anyplace you would have originally referenced B2.
If, for some reason, you cannot create a data table for your item names and codes, you could approach the problem by creating an array formula:
As with all array formulas, you enter this one by pressing Ctrl+Shift+Enter. The biggest drawback to it is that it can quickly become unwieldy to keep the formula updated and there is a "viability limit" on how many pairs of codes and items you can include in the formula. (The limit is defined by formula length, so it depends on the length of your item names.) Also, this approach is good to only return the item code in another cell, rather than including it as part of a larger formula.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12078) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Returning Item Codes Instead of Item Names.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
The COMBIN function is used to determine the number of combinations that can be made from a group of elements. This tip ...Discover More
You may want to use Excel to display dates using a different language than your normal one. There are a couple of ways ...Discover More
Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive ...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.