Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

28 Microsoft Excel Version 2002 Step by Step Courseware Instructor Guide

Using HLOOKUP and VLOOKUP Functions


Excel provides two lookup functions that can be used to retrieve informa-
tion stored in a table: VLOOKUP and HLOOKUP. A lookup function is a
Ex2002e-4-2
good way to search for and insert a value in a cell when the desired value
is stored elsewhere in the worksheet. A lookup function searches rows or
columns in a specified range (called a lookup table in Excel). Both func-
tions use the same arguments (with one exception, as explained below).
An argument refers to the values that a function uses to perform opera-
tions or calculations. The type of argument a function uses is specific to
the function.
The VLOOKUP and HLOOKUP functions locate a specific value in a
table (any row-and-column range or a named range). This value might be
the name of a person, for example. These functions retrieve corresponding
information from the table that relates to this value (such as the person’s
birth date) and place the data into the active cell. You indicate how many
rows or columns that the desired value is from the lookup value.
For example, the recreation director at Adventure Works keeps a table of
names, room numbers, and birthdays for the children of guests at the re-
sort. Each day, she uses the VLOOKUP function to search for that day’s
date in the table and display the name and room number of each child
whose birthday is that day. She then uses this information to send birthday
gifts to the appropriate rooms.

tip
The LOOKUP function uses specific criteria to search for a value in a single
column or row of a table, and then it displays a value from the corresponding
position in a second table. For example, suppose you had a worksheet in
which one column contains a room number and the second column con-
tains the room type. You could perform a lookup for room 102 in the first
column. Excel would then return the room type stored in the correspond-
ing column. For example, a lookup for room 102, located in the third row
of the first column, would return Single Room/Queen Bed from the third
row of the second column. The chief advantage of the LOOKUP function
is that you do not need to know the row or column position where the
desired lookup information is stored.

The HLOOKUP function looks in rows (a horizontal lookup), and the


VLOOKUP function looks in columns (a vertical lookup). Each function
can use up to four arguments. All of the arguments below are required
except for range_lookup:
HLOOKUP(lookup_value,table_array,row_index_num,range_lookup)
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
Lesson 2 Working with Data and Named Ranges 29

Argument Description
lookup_value The value to be found in the row or the column.
The lookup value can be a constant value, a text
contact enclosed in quotation marks, or the ad-
dress or name of a cell that contains a numeric or
text constant.
table_array The table of information in which data is looked
up. This can be the row-and-column coordinates
of the table or the name of a range.
row_index_num The numeric position of the row that is to be
searched (used only for HLOOKUP).
col_index_num The numeric position of the column that is to be
searched (used only for VLOOKUP).
range_lookup If the function is to return the nearest value, even
if there is no match, this value should be set to
TRUE. If an exact match is required, this value
should be set to FALSE.

To better understand the use of VLOOKUP and HLOOKUP, briefly review


the following lookup table that the sales manager of Adventure Works cre-
ated to formulate end-of-year bonuses for the sales staff. Years is column 1
in the lookup table, Standard Bonus is column 2 in the lookup table, and
Excellence Award is column 3. “Years, Standard Bonus, Excellence
Award” is row 1 of the lookup table:

Column1 Column2 Column 3


Bonus Schedule
Row 1 Years Standard Bonus Excellence Award
Row 2 1 $50.00 $200.00
Row 3 3 $75.00 $300.00
Row 4 5 $100.00 $400.00
Row 5 7 $250.00 $1,000.00
Row 6 9 $500.00 $2,000.00
Row 7 11 $750.00 $3,000.00
Row 8 13 $1,000.00 $4,000.00
Row 9 15 $1,500.00 $6,000.00

Now review the following lookups and their results:

● =VLOOKUP(D7,Bonustable,2) Result: $1,000


VLOOKUP looks in cell D7 of the above worksheet and finds the
value 13 stored there. The function then looks in the Bonustable
range for a matching value and finds it in the second-to-last row.
The function then retrieves the value ($1,000.00) in column 2 of
the same row and places the value in the active cell.
● =VLOOKUP(12,Bonustable,2,TRUE) Result: $750.00
VLOOKUP looks for the value 12 in the Bonustable range and
does not find it. However, because the Range_lookup argument is
set to TRUE, the function finds the closest (next lower) value, 11
30 Microsoft Excel Version 2002 Step by Step Courseware Instructor Guide

in this case. The function then returns the value ($750.00) in


column 2 of the same row and places the value in the active cell.
● =VLOOKUP(14,Bonustable,2,FALSE) Result: #N/A
VLOOKUP looks for the value 14 in the Bonustable range and
does not find it. Because the Range_lookup argument is set to
FALSE (which means an exact match is required), the function
places the #N/A error value in the active cell to indicate that no
match existed.
● =HLOOKUP(“StandardBonus”,Bonustable,4,FALSE) Result:
$100.00
HLOOKUP looks for the value “Standard Bonus” in the
Bonustable range, finds the value in column 2, and then returns
the value ($100.00) in row 4 of the column.
Show slides 02 Ranges 12–13, In this exercise, you use the VLOOKUP function to calculate the yearly
Using the HLOOKUP and bonus, based on years of service, for an Adventure Works employee
VLOOKUP Functions.
named Benson. Then you use the fill handle to copy the VLOOKUP func-
tion to cells for other employees. You also use the HLOOKUP function to
return the “Excellence Award” value in a specified row of a lookup table.

Be careful not to insert any spaces 1 Open the Employee History Bonus workbook.
when you type this formula. 2 Click cell E7, and type =vlookup(d7,bonustable,2).
Cell D7 contains the number of years worked, which is the lookup
Bonustable has already been defined value. VLOOKUP looks for a match to the D7 value in the bonustable
as a range name for cells A20:C28.
You can verify this by clicking the range (A20:C28), and then it looks in the second column, where it
Name down arrow and clicking finds the match.
Bonustable. Arguments used in a
VLOOKUP or HLOOKUP function are 3 Press Enter.
not case-sensitive, so you can type
them in either uppercase, lowercase, The result of the function ($1000.00) appears in cell E7.
or any combination of uppercase and 4 Click cell E7, and drag the fill handle down to cell E15.
lowercase characters. Also the
VLOOKUP and HLOOKUP function The bonuses for the other employees are calculated.
names are not case-sensitive.

You can also access the VLOOKUP


and HLOOKUP functions from the
Function Arguments dialog box,
which you open by clicking Function
on the Insert menu or by clicking the
Insert Function button next to the
Formula Bar.

5 Click cell F7.


Lesson 2 Working with Data and Named Ranges 31

Explain that if range_lookup is 6 Type =hlookup(“excellence award”,bonustable,8,false), and press


not set to false, Excel uses the Enter.
default value true for the
range_lookup argument. Excel searches for the text string “excellence award” in the first row
However, a range_lookup of the bonustable range and locates it in column C. Then Excel re-
argument of true works only if
the values in the first row of trieves the value ($4,000.00) in cell C8 and places it in the active cell.
the table (Years, Bonus, and
Excellence Award) are in
ascending alphabetical order,
which they are not. The
range_lookup argument must
be set to false for the lookup in
step 6 to work properly.

7 Save and close the workbook.

tip
If you have trouble remembering the syntax for an HLOOKUP or VLOOKUP
function, you can use the Function Arguments dialog box to help you
enter the lookup information. On the Insert menu, click Function or click the
Insert Function button next to the Formula bar to display a list of catego-
ries and function names. In the categories list, click Lookup & Reference. In
the function list, click VLOOKUP or HLOOKUP, and click OK. Excel will then
prompt you for the information required to perform the lookup.

You might also like