Complex Lookup Formulas

by Allen Wyatt
(last updated June 1, 2013)

2

Eddie has a series of part numbers in the format 123/45678 or 011/00345. He needs to look up the name of the corresponding part number from a different table. This table consists of three columns. The first column contains the portion of the part number before the slash (such as 123 or 011) and the second column contains the portion after the slash (such as 45678 or 00345). The third column contains the name that Eddie want to look up.

Part of the problem Eddie is having is that in the table, the two columns that each contain a portion of the part number are numeric values. Thus the full part number isn't 011 and 00345, but 11 and 345. Eddie is wondering how to put together a lookup formula for the part numbers (123/45678 or 011/00345) to return the proper part name from the table.

To start with, you need to make some changes to the table that contains the part numbers. The first two columns should be formatted as text, not as numbers. This will treat the values in those columns as text, so that when you enter "011" in the first column, it retains the leading zero. If you have already entered the value as 011 before formatting the column as text, it will still be displayed as 11 (without the leading zero). You will need to not only change the format of the column, but also re-enter any part-number fragments that contain leading zeros.

Next you need to make sure that your part number table includes column headers. For this example, make sure the three column headers are Left, Right, and Name. (You can make these headers bold and underlined, which helps set them off from the values in each column.) Then, create names for the individual columns by following these steps:

  1. Select the cells in the part number table. Make sure you also select the newly created headers for each column of the table.
  2. Click Insert | Name | Define. Excel displays the Create Names dialog box.
  3. Make sure that only the Top Row check box is selected.
  4. Click OK.

With your part-number table prepared, you are now ready to look up part numbers. In the cells just to the right of your lookup values (123/45678 and 011/00345) you are going to enter an array formula. Assuming that the first part number is in cell A1, you would enter the following array formula in cell B1:

=INDEX(Name,MATCH(A1,Left&"/"&Right,0))

Remember that to denote this as an array formula you enter it by pressing Shift+Ctrl+Enter. The formula then appears in the Formula Bar with {braces} around it. You can copy the formula down to the other cells in column B, as necessary.

The formula works by pulling the value from the Name column of the table when the corresponding Left-column value concatenated with a slash and the Right-column value matches whatever is in cell A1. If there is no match, the formula returns a #N/A error value, otherwise it returns the desired part number.

Note that this approach will work only if you format the first two columns of your part-number table as text and make sure that the various cells contain any leading zeros. If, for some reason, you cannot format the first two columns of the table in this way (perhaps there are too many of them), then you need to change the lookup formula you are using:

=INDEX(Name,MATCH(A1,TEXT(Left,"000")&"/"&TEXT(Right,"00000"),0))

Note that this version of the formula (which should still be entered as an array formula) uses the TEXT function in two places, to convert the values from the Left and Right columns so they have leading zeros.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2787) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Setting Your Default Document Directory

Word allows you to specify where it should start looking for your documents. This setting can come in handy if you store your ...

Discover More

Determining If the End of a Text File Has Been Reached

When writing a macro that processes a text file, you may need to know when the end of the file has been reached. This is easy ...

Discover More

Converting Time Notation to Decimal Notation

Want to convert an elapsed time, such as 8:37, to a decimal time, such as 8.62? If you know how Excel stores times ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

MORE EXCELTIPS (MENU)

Viewing Formula Results

When editing information in a cell, you may need to know the result of a portion of your formula. The shortcut described in ...

Discover More

Matching Formatting when Concatenating

Convert a numeric value to text and you may be surprised by how Excel displays the value. Here's a run-down on exactly what ...

Discover More

Finding the Directory Name

Need to know the directory (folder) in which a workbook was saved? You can create a formula that will return this information ...

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 for this tip:

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 1?

2013-06-04 09:29:35

Dave Kerr

Hi,

Suppose you have your dates in cells A1:A7 and the corresponding values in cells B1:B7. Here is a quick solution for you.

Go to cell D1 and enter the formula =YEAR(A1). Then copy this down to fill cells D2:D7. Select the cells D1:D7 and name the range "Years".

Next, select the used cells in column B and name the range "Items".

Next, go to where you want your year totals to appear and type once only each year for which you want a total. For example, in Cell E1 type 2011, in E2 type 2012 and in E3 type 2013.

Finally, in Cell F1, enter the formula =SUMIF(Years, F1, Items). Copy the formula to F2 and F3 and there you have your totals by year!

If you add additional rows of data, don't forget to extend the named ranges to match. You can place your totals and year values anywhere you wish, of course!

I hope you find this useful.
Dave


2013-06-03 02:22:57

Jayesh Bhagat

Hi Allen,
I have in a column A certain dates mentioned in mm/dd/yyyy format and in column B certain numbers against each of those dates. I want to use a sumifs function in certain cell such that it sums only those values where the year in column A is the previous year (that is, Yearnow()-1. Please advice


This Site

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.

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.

Links and Sharing