You are on page 1of 8

Unit 16: Lookup & Reference Functions

16.0 Introduction
One of the most important features of Excel is its ability to look for a specific value within a large number of cells containing data, and return a value from that row (or column). The easiest way to do that is to use the VLOOKUP and HLOOKUP functions. If you do a lot of analysis of large databases it will probably be worth you learning the slightly more complicated and much more powerful INDEX-MATCH combination of functions.

16.1 VLOOKUP
The VLOOKUP function looks for a specified value in the left-most column of a table of data and returns a value from that row in one of the columns to the right. Consider the following data about the launch date of some popular websites:

Assume the list goes on for thousands of lines. Suppose you are only interested in the four social networking sites. You could create a small list with just the sites you are interested in (column D) and then use VLOOKUP to look them up in the large table and return the corresponding launch dates. Type into cell E2:

2013 Excel with Business

Unit 16: Lookup & Reference Functions

=VLOOKUP(D2,A:B,2,FALSE) to give:

Where: D2 is the value were looking up. Note that writing Facebook.com for this argument would have achieved the same result, but we would not have been able to copy the formula down to other rows without changing it A:B is the range of the data were looking in. Note, the absence of numbers in this reference means the whole column is searched. Although this does allow for additional entries in the columns this should be used with care. Excel 2007 and 2010 worksheets have over 1,000,000 rows. Referring to many whole columns can slow down your calculations. 2 is the column number of the value we want returned. So in this case, the column were interested in (Launch year) is the second one so we put 2 FALSE indicates that we are looking for an exact match. Leaving this blank or writing TRUE would ask Excel to look for an approximate match. Note that this doesnt mean Excel will just find the closest match, Excel will find the largest value that is equal to or smaller than the value were looking for. For an approximate match to work, the first column of our table of data must be sorted in ascending order.

In this example, we have a small table of prices for a product showing the date from which each price became operative. If we wanted to find out which price to use for an invoice on a certain date, we couldnt use the exact form of VLOOKUP() because the table includes only 4 dates out of the hundreds we might need to use. We have set up the data with the first column sorted in ascending order and we can see the effect of using an exact VLOOKUP()

2013 Excel with Business

Unit 16: Lookup & Reference Functions

with FALSE as the fourth argument where there is a match(E2), and no match (E3), and also the approximate form of VLOOKUP() (E4) with TRUE as the fourth argument. For the formula in E4, VLOOKUP() finds the largest value in column A that is smaller than or equal to 31/10/12 in this case 17/8/12, hence the result of 17.00.

Limitations
The data you are looking up must be in the left-most column of the range you select

16.2 HLOOKUP
You can also LOOKUP horizontally arranged data. Suppose we wanted to undertake the same exercise for the same data but that our data is arranged horizontally:

Then by typing the sites were interested in into cells B4:E4 and then the following formula into cell B5: =HLOOKUP(B4,B1:AN2,2,FA LSE) We get:

In fact, it would be better (at least visually) in this kind of example to reformat the text vertically and use a VLOOKUP. If you find yourself using HLOOKUP its worth asking yourself if the datas set up the best way. You can convert vertically-arranged data to horizontally arranged data through a Paste Special Transpose: Home > Paste > Paste Special > Transpose

2013 Excel with Business

Unit 16: Lookup & Reference Functions

Since most databases display data down columns rather than across rows, VLOOKUP is the more useful of the two. The limitations of VLOOKUP apply to HLOOKUP too.

16.3 MATCH
The MATCH function is really a lookup function which doesnt bring back any data. It just tells you if it found the value you asked it to look for and if so, where it was found. There are three arguments in a MATCH function: what youre looking for, where youre looking for it and the kind of match you are trying to make. Using our popular websites example, suppose we think of a couple more social networking sites (Bebo and Friendster) and we want to see if they appear in our big database. Type into cell E2: =MATCH(D2,A:A,0) And you would see something like:

Where: D2 is what were looking for (in row 2 this is Facebook.com)

2013 Excel with Business

Unit 16: Lookup & Reference Functions

A:A is the column were looking in 0 means that were looking for an exact match (just as with VLOOKUP and HLOOKUP its a good idea to use the exact match form when you are expecting an exact match; if you use the approximate match forms then the data must be sorted accordingly)

The resulting table is:

The 4 in cell E2 shows the position at which Facebook.com appears in column A (its the 4th item in the range we select). Note that, in this case, this includes the header. If wed wanted that removed we would have typed =A2:A1048576 instead of A:A. Similarly for 6, 13, 26. The #N/As in cells E6 and E7 indicate that neither Bebo.com nor Friendster.com is in the big list.

16.4 INDEX-MATCH
The INDEX-MATCH combination is not easy but well worth taking the time to learn, particularly if you frequently work with a lot of data. INDEX-MATCH has advantages over VLOOKUPs: It can be used on data arranged in columns or rows You can find a column based on matching the heading rather than having to choose a particular number column

INDEX
The INDEX function is fairly simple and can also be used on its own. It has two arguments: the list you want Excel to look at and the number in that list that you want returned. So if you wanted to have the 14th website in the list below returned, you would write: =INDEX(A2:A40,14)

2013 Excel with Business

Unit 16: Lookup & Reference Functions

And ESPN.go.com will be returned. Suppose that you have another database of website information on user ratings over various geographies, ordered alphabetically:

You want to consolidate the two databases into one master database with all of this information. First you need to decide if you want to add the ratings information to the launch spreadsheet or vice versa. This might depend on which order and format takes precedence. Lets say were adding ratings data to launch data.

2013 Excel with Business

Unit 16: Lookup & Reference Functions

Then in that database we type: =INDEX(Ratings!B:B,MATCH(Launch!A2,Ratings!A:A,0) Where: the yellow part of the formula indicates where we have asked Excel to look (column B of the ratings sheet) the green part returns the position in the ratings column A (where the sites are listed alphabetically) that Google.com shows up. Lets say this is the 100th place down The INDEX therefore knows to return the 100th Rating in column B of the Ratings sheet

Now, to get ALL the data from the ratings sheet we want to copy a version of the formula down, and to the right. Since we are always going to want to use match from the A column of the Launch sheet (but not always the same row) to the A column of the Ratings sheet, we can fix some cell references (see Unit 11: Cell References) to: =INDEX(Ratings!B:B,MATCH(Launch!$A2,Ratings!$A:$A,0)) Then extending the formula down and right gives:

2013 Excel with Business

Unit 16: Lookup & Reference Functions

Beware
Like any other Excel formula and function it is easy to enter incorrectly (and harder to spot the error than for some). You must therefore take care: To carry out spot checks. In the example above you might choose a cell randomly, lets say F15 to check that Go.com was rated 9.8 in the Ratings sheet. Sorting data. Make sure you create INDEX-MATCH functions in such a way that they still return the correct result if the sort order of the data is changed. To keep precise data. While we advocate the use of the exact match type, this does require that the data you are looking amongst correspond exactly to the value you are looking up. Sometimes you are a simple operation away from achieving this. For example, if the websites in the Ratings sheet all had www. in front of them, we might have to add these to the corresponding entries in the Launch sheet (with &) or by removing them from the Ratings sheet (using Find & Replace or LEFT & LEN).

2013 Excel with Business

Unit 16: Lookup & Reference Functions

You might also like