How To Do VLOOKUP in Excel
How To Do VLOOKUP in Excel
When I first heard about this powerful Excel function in 2005, I took a look at the
help file and syntax. I then rolled my eyes.
VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup])
It looked too difficult, and I couldn’t see the immediate benefit. But sometimes,
pushing through difficulties can make things easier in the long run.
When it comes to learning Microsoft Excel formulas and functions, I like to start
with an easy example. This VLOOKUP tutorial will provide two examples using
different arguments and lookup values.
Article Contents
What is Excel VLOOKUP Function?
Example 1 - Approximate Match
Understanding the Arguments
Table Array Rules & Caveats
Using VLOOKUP in Our Formula
Example 2 - Multiple Sheets & Exact Match
Defining the Argument Values
Additional VLOOKUP Example Resources
This lookup column could be on the same worksheet you’re viewing or another
within your workbook. The function requires a common field or key and
four arguments. The function allows you to specify whether to use an exact
match or an approximate match.
Let’s put these terms in context and give a real example of where and how they
might be used. When I do website analysis, I use several tools. I export data from
each service into a .CSV file or Excel .XLSX file. Each tool has its own file that I use
to create a sheet within a workbook.
One cell reference contains the voter’s birth date. However, I didn’t want the
voter’s birth date to show on the final distributed files. But, I did want to do some
age analysis.
Instead, I decided to create a segment based on age ranges and a lookup
formula. Excel would do a vertical lookup that returns the matching value from
one column to the desired cell. Rather than showing a voter was 28, I would
define them as “Young.”
The small table in columns H and I with blue headings is the lookup table.
Microsoft refers to this as a table_array. This is where I’ve defined my 4 age
segments.
The way “Segment” works is if a voter is under 21, they are “New.” From 21-38,
they are “Young.” From 39-59, they are “Mature.” And if they are 60 or older, they
are “Senior.”
In Sophia’s case, Excel would take her age of 39 from cell D2 and return the
closest match from Column H. Both these columns contain age data, which is our
common key.
When Excel found a match, it would go to Column I and get the Label. The
returned value was then copied to cell E2, the Segment. It might help to think of
columns as being vertical. After all, this is a vertical lookup.
You might notice that the lookup table doesn’t list every age. It doesn’t have to
because I’m using an approximate match. I’m telling Excel to find me the closest
age.
For example, the next voter Evelyn Bennett is 51, but there is no value for 51 in
Column H. In this case, 51 falls between 39 and 59, so she is also labeled
“Mature.”
As we stated, to use the VLOOKUP function, there needs to be a common key. In
this case, it’s age. Both columns D and H contain ages. The column headings and
cell contents can be different and don’t have to be an exact match.
=VLOOKUP(D2,$H$2:I$5,2,TRUE)
cell range
true/false logical value
number
Using the formula from cell D2, here’s how these four arguments work.
2. Table_array – This is the cell range for your lookup table. This range lookup
can be on your existing worksheet or another worksheet. In this example, I have a
small table with the age groupings and corresponding labels.
When we count, we’re counting the columns on the lookup table. Even though
the “Label” column is Column I or the 9th column, it’s the 2nd column on the
lookup table. Some people call this a Column Index.
4. Range-lookup – this field defines how close a match should exist between
your Lookup_value (D2) and the value in the leftmost column on our lookup
table. In our case, we want an approximate match, so we’ll use “TRUE.”
Table Array Rules & Caveats
There are several rules to remember about this table array.
After you define your lookup range of cells, you can press F4. This will cycle
through absolute and relative cell references. You want to select the option that
includes a $ before your Column and Row. You can get around this if you know
how to use Excel name ranges.
This coding wasn’t intuitive. For example, “D” was for the “American Independent
Party,” but some thought it meant “Democratic Party.” Another difference was we
needed an exact match for Party.
For illustration purposes, I have overlaid the Party Codes worksheet on top to
show the relationships.
The other item of interest is that when you build these functions, Excel displays
the result in the Formula result = text line. This is great feedback that can show
if your function is on target. In our example, we can see Excel looked up the
Pcode of “A” and returned the Political Party “Democratic.”
VLOOKUP is a powerful Excel function that can leverage spreadsheet data from
other sources. There are many ways you can benefit from this function. In this
example, I used a 1:1 code translation, but you could also use it for group
assignments. For example, you could assign state codes to a region such as CT,
VT, and MA to a “New England” region.
One important note about using Excel functions and formulas is you want to be
careful when deleting columns. For example, in the final spreadsheet I distributed,
I omitted the Age column. After completing my VLOOKUP and got my segments,
I copied the cell values to a new Excel worksheet. If I had just deleted Column D,
my Excel formula would’ve returned an error.