Professional Documents
Culture Documents
Week 7.2.
Using Formulas for Lookups
Leveraging Excel’s Lookup Functions
Finding data in a list or table is central to many Excel formulas. Excel provides several functions
to assist in looking up data vertically, horizontally, left to right, and right to left. By nesting some
of these functions, you can write a formula that looks up the correct data even after the layout of
your table changes.
1|P a g e
Data and Computing Skills
The user will select an employee ID from a data validation list in cell L3 (see Figure). From that
piece of data, the employee’s name, address, and other information will be pulled into the form.
The formulas for the paystub form in Figure are shown here:
• Employee Name
=VLOOKUP($L$3,$B$3:$I$12,2,FALSE)
• Pay
=VLOOKUP($L$3,$B$3:$I$12,5,FALSE)/VLOOKUP($L$3,$B$3:$I$12,4,FALSE)
• Taxes
=(M7-O8-O9)*VLOOKUP($L$3,$B$3:$I$12,6,FALSE)
• Insurance
=VLOOKUP($L$3,$B$3:$I$12,7,FALSE)
• Retirement
=M7*VLOOKUP($L$3,$B$3:$I$12,8,FALSE)
• Total
=SUM(O7:O10)
• Net Pay
=M7-O11
The formula to retrieve the employee’s name uses the VLOOKUP function. VLOOKUP takes four
arguments: lookup value, lookup range, column, and match. VLOOKUP will search down the first
column of the lookup range until it finds the lookup value. Once the lookup value is found,
VLOOKUP returns the value in the column identified by the column argument. In this case, the
column argument is 2, and VLOOKUP returns the employee’s name from the second column of
the lookup range.
2|P a g e
Data and Computing Skills
The other formulas also use VLOOKUP with a few twists. The address and insurance formulas
work just like the employee name formula, but they pull from a different column. The pay
formula uses two VLOOKUPs; one is divided by the other. The employee’s annual pay is pulled
from the fifth column, and that is divided by the frequency from the fourth column, resulting in
the pay for one paystub.
The retirement formula pulls the percentage from the eighth column and multiplies that by the
gross pay to calculate the deduction. Finally, the taxes formula deducts both insurance and
retirement from gross pay and multiplies that by the tax rate, found with VLOOKUP pulling from
the sixth column.
Of course, payroll calculations are a little more complex than this, but once you understand how
VLOOKUP works, you can build ever more complex models.
The HLOOKUP function has the same arguments as VLOOKUP. The H in HLOOKUP stands for
“horizontal,” while the V in VLOOKUP stands for “vertical.” Instead of looking down the first
3|P a g e
Data and Computing Skills
column for the lookup_value argument, HLOOKUP looks across the first row. When it finds a
match, it returns the value from the second row of the matching column.
https://support.microsoft.com/en-us/office/apply-data-validation-to-cells-29fecbcc-d1b9-
42c1-9d76-eff3ce5f7249
4|P a g e
Data and Computing Skills
Figure shows a list of companies and CEOs. The other list shows CEOs and salaries. A VLOOKUP
function is used to combine the two tables. But we obviously don’t have salary information for
all of the CEOs, so we have a lot of #N/A errors.
=VLOOKUP(C3,$F$3:$G$11,2,FALSE)
In Figure the formula has been changed to use the IFERROR function to return a blank if there’s
no information available.
=IFERROR(VLOOKUP(C3,$F$3:$G$11,2,FALSE),"")
The IFERROR function accepts a value or formula for its first argument and an alternate return
value for its second argument. When the first argument returns an error, the second argument
is returned. When the first argument is not an error, the results of the first argument are
returned.
In this example, we’ve made our alternate return value an empty string (two double quotes with
nothing between them). That keeps the report nice and clean. But you could return anything you
want, such as “No info” or zero.
5|P a g e
Data and Computing Skills
XLOOKUP function
Use the XLOOKUP function to find things in a table or range by row. For example, look up the
price of an automotive part by the part number, or find an employee name based on their
employee ID. With XLOOKUP, you can look in one column for a search term and return a result
from the same row in another column, regardless of which side the return column is on.
Note: XLOOKUP is not available in Excel 2016 and Excel 2019, however, you may come across a
situation of using a workbook in Excel 2016 or Excel 2019 with the XLOOKUP function in it
created by someone else using a newer version of Excel.
Syntax
The XLOOKUP function searches a range or an array, and then returns the
item corresponding to the first match it finds. If no match exists, then XLOOKUP can return
the closest (approximate) match.
Argument Description
lookup_value The value to search for
Required* *If omitted, XLOOKUP returns blank cells it finds in lookup_array.
lookup_array The array or range to search
Required
[if_not_found] Where a valid match is not found, return the [if_not_found] text you
Optional supply.
If a valid match is not found, and [if_not_found] is missing, #N/A is
returned.
[match_mode] Specify the match type:
Optional 0 - Exact match. If none found, return #N/A. This is the default.
-1 - Exact match. If none found, return the next smaller item.
1 - Exact match. If none found, return the next larger item.
2 - A wildcard match where *, ?, and ~ have special meaning.
[search_mode] Specify the search mode to use:
Optional 1 - Perform a search starting at the first item. This is the default.
-1 - Perform a reverse search starting at the last item.
2 - Perform a binary search that relies on lookup_array being sorted
in ascending order. If not sorted, invalid results will be returned.
-2 - Perform a binary search that relies on lookup_array being sorted
in descending order. If not sorted, invalid results will be returned.
6|P a g e
Data and Computing Skills
Translated into plain English, it says: search for the F1 value in A2:A6 and return a value from
C2:C6 in the same row. No column index numbers, no sorting, no other ridiculous quirks of
Vlookup!
7|P a g e