Lookups in Excel: VLOOKUP and INDEX with MATCH
Type a code once and let the sheet fill in the name, the price or the discount. Exact and approximate lookups on an invented invoice, and INDEX with MATCH for when the answer sits to the left.
- Level
- Beginner
- Reading time
- About 12 minutes
- Know this first
- IF, AND, OR and IFERROR
By the end you will be able to:
- look up a value from a table with VLOOKUP and lock the table
- say when to ask for an exact match and when an approximate match fits
- price a discount or fee tier from a sorted table
- combine INDEX and MATCH to look to the left
- read #N/A and decide whether to handle it
Finding a value by its name
Real sheets rarely hold everything in one place. A price list lives on one sheet, the orders on another, and a discount schedule somewhere else. A lookup finds a value in a table by matching a key, such as a product code, so that you type the code once and the sheet fills in the rest.
This lesson covers the two classic tools, VLOOKUP and the pair INDEX and MATCH, and the two ways of matching: exactly and approximately. It follows the IF lesson, because a lookup table replaces a long chain of nested IFs. The example is an invented invoice.
VLOOKUP: exact match
VLOOKUP(lookup_value, table, column_number, match_type). It looks for the lookup value in the first column of the table, then returns the value from the numbered column in the same row. Column 1 is the first column of the table, which is the one that is searched.
In the invoice, =VLOOKUP($A2, $G$2:$I$6, 3, FALSE) finds the code in A2 in the first column of the price list and returns the third column, the price. The table is locked with dollar signs so that the formula can be copied down. The last argument, FALSE, asks for an exact match, so a code that is not in the list gives #N/A instead of a near miss. For looking up names and prices, always ask for the exact match.
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Code | Item | Price | Qty | Total | Code | Item | Price | |
| 2 | P200 | Pen box | $12.00 | 3 | $36.00 | P100 | Notebook | $4.50 | |
| 3 | P100 | Notebook | $4.50 | 10 | $45.00 | P200 | Pen box | $12.00 | |
| 4 | P500 | Desk lamp | $24.00 | 2 | $48.00 | P300 | Stapler | $8.25 | |
| 5 | P300 | Stapler | $8.25 | 2 | $16.50 | P400 | Folder pack | $6.75 | |
| 6 | Order value | $145.50 | P500 | Desk lamp | $24.00 |
The order value is $145.50. The total for each line is the looked-up price times the quantity, and nothing in the table was retyped.
Approximate match: bands and tiers
The other match type, TRUE, is made for bands such as discount tiers, fee schedules and tax brackets, where you want the band a number falls into and not an exact hit. The first column must be sorted from smallest to largest. The lookup then returns the row with the largest value that does not exceed what you searched for.
The tiers here are: nothing off below 100, 2% from 100, 5% from 250 and 8% from 500. An order of 145.50 falls in the 100 tier. 249.99 stays in the 100 tier, and exactly 250 moves up to the next. If the table is not sorted, an approximate lookup can give a wrong answer without any error, so sort it.
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | From | Discount | Order value | Discount rate | |
| 2 | $0 | 0% | $50.00 | 0% | |
| 3 | $100 | 2% | $100.00 | 2% | |
| 4 | $250 | 5% | $145.50 | 2% | |
| 5 | $500 | 8% | $249.99 | 2% | |
| 6 | $250.00 | 5% | |||
| 7 | $1,000.00 | 8% |
For the invoice, $145.50 earns 2%, a discount of $2.91, leaving $142.59 to pay.
| Row | A | B |
|---|---|---|
| 9 | Order value | $145.50 |
| 10 | Discount rate | 2% |
| 11 | Discount | $2.91 |
| 12 | To pay | $142.59 |
INDEX and MATCH: looking in any direction
VLOOKUP has one limit: it can only return values to the right of the column it searches. To go from an item name to its code, which sits to the left, use two functions together. MATCH(value, range, 0) returns the position of the value in a range, and INDEX(range, position) returns the item at that position in another range.
Looking up Desk lamp, MATCH finds it fifth in the item column, and INDEX takes the fifth cell of the code column, P500. The third argument, 0, again means an exact match. Because the search range and the return range are separate, either can be anywhere, and inserting a column into the table does not break the formula, which a numbered column in VLOOKUP can.
| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | Code | Item | Price | Item wanted | Desk lamp | |
| 2 | P100 | Notebook | $4.50 | Position | 5 | |
| 3 | P200 | Pen box | $12.00 | Code | P500 | |
| 4 | P300 | Stapler | $8.25 | Price | $24.00 | |
| 5 | P400 | Folder pack | $6.75 | Misspelled | Desk lamps | |
| 6 | P500 | Desk lamp | $24.00 | Raw result | #N/A | |
| 7 | With IFERROR | not found |
The misspelled name gives #N/A, which is the correct answer to the question “where is this item?”. Wrapping the formula in IFERROR turns it into a plain message. As with any IFERROR, use it only where you have a reason to expect the failure.
Try it yourself
The practice workbook holds the three sheets drawn above, and a sheet with a brokerage-style fee schedule in which the fee depends on the size of the trade. Fill in the rates with an approximate-match lookup, then check the answers sheet.
Download the practice workbook (free .xlsx, no sign-up).
What this lesson leaves out
- An invented price list. The codes, items, prices and discount tiers are made up to show the mechanics. They are not real prices or a real fee schedule.
- Two tools. Newer Excel has XLOOKUP, which does both jobs. It is left out because it is missing from older versions and from some other programs, and it works on the same idea.
- Single lookups. Looking up on two keys at once, such as a customer and a product, needs more advanced formulas and is not covered.
- No data checks. Dropdown lists can stop a code being mistyped. They are useful but outside this lesson.
Common mistakes
Leaving out the last argument
If match_type is omitted, VLOOKUP assumes TRUE, an approximate match, and an unsorted table can then return a wrong value silently. Type FALSE for exact lookups.
Searching a table that is not sorted
Approximate matches need the first column in ascending order. Sort the tiers before using TRUE.
Forgetting to lock the table
Without dollar signs the table range slides down as the formula is copied, and later rows start returning #N/A.
Counting the wrong column
The column number counts from the first column of the table, not from column A of the sheet.
Text that looks identical but is not
A trailing space, or a number stored as text, stops a match. If a lookup fails, check the key cells.
Questions to answer
1. In the invoice, what formula finds the price for the code in A2, and why is the last argument FALSE?
Show the working
=VLOOKUP($A2,$G$2:$I$6,3,FALSE). FALSE asks for an exact match, so an unknown code returns #N/A and not a nearby price.
2. Using the tier table, what discount rate do orders of 100, 249.99 and 250 get?
Show the working
2%, 2% and 5%. An approximate lookup returns the largest tier that does not exceed the value, and 250 is itself a tier.
3. What do MATCH("Desk lamp", B2:B6, 0) and INDEX(A2:A6, 5) return?
Show the working
MATCH returns 5, the position of Desk lamp in the list. INDEX then returns the fifth code, P500.
4. The invoice totals $145.50 and gets a 2% discount. What is the amount to pay?
Show the working
Discount is 145.50 × 0.02 = $2.91, so $142.59 is to pay.
5. In the fee schedule, a trade of 4,999 and a trade of 5,000 pay different rates. What are the fees?
Show the working
4,999 falls in the 1,000 tier at 0.8%, a fee of $39.99. 5,000 reaches the next tier at 0.5%, a fee of $25.00, so the larger trade pays less. The other fees are 8.00, 8.00 and 75.00.
Where this is used
- A small business fills in invoice prices from a master price list.
- A payroll sheet looks up a tax rate or allowance from a table of bands.
- A bank's fee schedule gives a different rate for each size of transaction.
- An analyst pulls a company's figures from a data sheet by ticker symbol.
- A shop applies volume discounts according to the size of an order.
Key terms
- Lookup
- Finding a value in a table by matching a key.
- VLOOKUP
- Searches the first column of a table and returns a value from the same row.
- Exact match
- A lookup that accepts only an identical key.
- Approximate match
- A lookup that returns the row with the largest key that does not exceed the value.
- MATCH
- Returns the position of a value within a range.
- INDEX
- Returns the item at a given position in a range.
- #N/A
- The error shown when a lookup finds nothing.
Questions people ask
Should I use VLOOKUP or INDEX and MATCH?
Either works for a simple lookup to the right. Use INDEX and MATCH when you need to look left or want formulas that survive columns being inserted.
Why does my VLOOKUP return #N/A when the item is there?
Usually the keys differ by a space, spelling or type, or the exact-match argument is missing and the table is unsorted.
Do these work in Google Sheets?
Yes. VLOOKUP, INDEX and MATCH behave the same way in Google Sheets and LibreOffice Calc.
What is the difference between 0 and FALSE in the last argument?
Excel treats them the same for these functions, so both ask for an exact match.
Sources and review
- Microsoft Support, Formulas and functions, the index of Excel functions, for the arguments each function takes.
- Microsoft Support, Switch between relative, absolute, and mixed references, for how a reference changes when a formula is copied and the keys that add the dollar signs.
How the numbers were checked: every sheet drawn in this lesson was built as a real workbook, recalculated with LibreOffice, and drawn from the recalculated cells, so the figures are what a spreadsheet really computes. The worked answers were recomputed the same way. These are standard functions with the same definitions in Excel and Google Sheets. The practice file is the same workbook.