The Excel VLookup (Vertical Lookup) worksheet function is versatile, has
database-like features and can be tricky to use correctly. I always have to
look in Excel Help to get this worksheet function right. The best way to see
how this function works is to do Insert, Function. In the "Or
select a category" drop down select the "All" category. In the "select a
function" then type a "v" and scroll down to VLOOKUP. Click the Help on
this function link.
So to see how the Excel worksheet function VLookup works, let's setup a range
that looks like:
Figure 1. Where we will be doing our VLOOKUP.
The VLOOKUP function requires at least three and up to four arguments. The syntax for
the VLOOKUP function is
=VLOOKUP("value that we are looking for", "worksheet range to look in", "if we
find what we are looking for go over this many columns and return the value in
that column to this worksheet cell", "do we want an exact match or not?")
Let's look at some examples.
Figure 2. VLOOKUP examples.
In Example 1, we want to lookup "ky" in the range defined by cells B2 to E3.
VLOOKUP always looks down the first column of the range, in this case column B.
If we find an exact match for "ky" we want to look over 2 columns (column B is
the 1st column) and return what we find. In this case we return the full state
name "Kentucky". The actual VLOOKUP function is in cell E7. The text of the
function (so you can see what the syntax looks like) is in cell G7.
Example 2 is similar to, but more versatile than, Example 1. We are still
looking for an exact match for "ky". But this time we don't "hard code" the
value "ky" in the first argument. We make reference to the cell address that
"ky" is in, namely cell C8. So the first argument of the VLOOKUP function has
C8 in it. And we don't hard code the column number 2 that we want to look over
across. We make reference to the cell the value 2 is in, namely cell D8. So the
third argument of the VLOOKUP function has D8 in it.
In Example 3, we change what we are looking up to "oh" and we change how many
columns we want to go across and return once we find an exact match. In this
case we want to go over to column E and return what is in the row that contains
"oh" in column B.
Finally, in Example 4, we try to find "ma" in column B and are unsuccessful. So
the VLOOKUP function returns the special value #N/A.