VLOOKUP and INDEX/MATCH
Read and repair VLOOKUP formulas, avoid the approximate-match trap, and build flexible and two-way lookups with INDEX and MATCH.
Welcome back!
Step 1 of 10Learn
The workbook you will inherit
Sooner or later you'll open a workbook built years ago and find hundreds of formulas like this:
=VLOOKUP(A2, Prices!$A$2:$D$900, 4, FALSE)
VLOOKUP stands for vertical lookup. Its arguments:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
It searches the first column of table_array for the lookup value and returns the value from column number col_index_num of that table, counting the first column as 1. In the example, it looks for A2 in Prices column A and returns the value in the fourth column, D.
The last argument is where the danger lives. FALSE (or 0) means exact match. TRUE (or 1) means approximate match, and approximate is the default if you leave the argument out. With approximate match on an unsorted list, VLOOKUP doesn't return #N/A for a missing code. It returns a value from some nearby row, and the result looks perfectly reasonable.
When you inherit a VLOOKUP, check the fourth argument first. If it's missing and the lookup is meant to be exact, add FALSE.
Step 2 of 10Practice · Spot the mistake
This price lookup returns plausible but wrong prices for codes that are not in the list, instead of #N/A. Click the part responsible.
Step 3 of 10Learn
Three more VLOOKUP limits
Even with FALSE in place, VLOOKUP has structural limits worth knowing, because they explain why formulas break.
It can't look left. The lookup column must be the first column of the table array. If product codes are in column C and names are in column A, VLOOKUP can't return the name without rearranging the data.
The column number is hard-coded. 4 means "the fourth column of the range." If someone inserts a column inside the price list, the price moves to column 5, but the formula still says 4 and starts returning the wrong field. No error appears.
It returns only the first match and searches top to bottom only, so "latest entry" lookups need workarounds.
A partial fix for the column number is MATCH: =VLOOKUP(A2, Prices!$A$2:$D$900, MATCH("Price", Prices!$A$1:$D$1, 0), FALSE) finds the Price column by its header. But if you're going to add MATCH, the cleaner design is the INDEX/MATCH pair, which you'll build next.
HLOOKUP is VLOOKUP's horizontal twin: it searches the first row and returns from a row number below. It has the same limits and the same approximate-match default.
Step 4 of 10Compare
Three ways to look up a value
| Aspect | VLOOKUP | INDEX/MATCH | XLOOKUP |
|---|---|---|---|
| Default match | Approximate (risky) | Set by MATCH; use 0 for exact | Exact |
| Return column left of lookup column | No | Yes | Yes |
| Survives inserted columns | No (hard-coded number) | Yes | Yes |
| Built-in not-found value | No | No | Yes |
| Works in older Excel | All versions | All versions | 2021 and Microsoft 365 |
Step 5 of 10Learn
INDEX and MATCH, one at a time
Before combining them, understand each function alone.
INDEX(array, row_num, [column_num]) returns the item at a given position. =INDEX(B2:B6, 3) returns the third value in B2:B6. Given a grid, =INDEX(B2:E6, 3, 2) returns the value in the third row and second column of the grid.
MATCH(lookup_value, lookup_array, [match_type]) does the opposite: it returns the position of a value. If A2:A6 holds Ana, Ben, Cho, Dev, Eli, then =MATCH("Cho", A2:A6, 0) returns 3, because Cho is the third item.
The third argument of MATCH works like VLOOKUP's trap, only worse: 0 is exact match, 1 (the default) finds the largest value less than or equal to the lookup value in an ascending list, and -1 finds the smallest value greater than or equal to it in a descending list. Always type the 0 for exact lookups.
Positions are relative to the range, not the sheet. Cho is in row 4 of the worksheet but position 3 of A2:A6. This is why the ranges given to INDEX and MATCH must start on the same row.
Step 6 of 10Practice · Work it out
A2:A6 contains Ana, Ben, Cho, Dev, Eli, and B2:B6 contains 41, 57, 38, 62, 45. What does =INDEX(B2:B6, MATCH("Dev", A2:A6, 0)) return?
Step 7 of 10Learn
Putting them together, in two directions
Nest MATCH inside INDEX and you get a lookup that works in any direction:
=INDEX(Prices[Price], MATCH(A2, Prices[Code], 0))
MATCH finds the row position of the code, INDEX returns the price at that position. The price column can be left or right of the code column, and inserting columns never breaks it, because each column is referenced directly.
The real payoff is the two-way lookup: find a value at the intersection of a row label and a column label. Imagine monthly sales by region with regions in A2:A6, months in B1:M1 and figures in B2:M6:
=INDEX(B2:M6, MATCH("West", A2:A6, 0), MATCH("Mar", B1:M1, 0))
The first MATCH supplies the row, the second the column, and INDEX returns the cell where they cross. Replace the quoted text with cells, say a region dropdown in P1 and a month dropdown in P2, and you have a small interactive report.
INDEX/MATCH works in every version of Excel, so it's still the standard choice when files go to people on older versions. On Microsoft 365, XLOOKUP is shorter for one-way lookups, but you'll keep seeing INDEX/MATCH everywhere.
Step 8 of 10Practice · Work it out
A grid has regions North, South, East, West in A2:A5, quarters Q1–Q4 in B1:E1, and values in B2:E5. The South row reads 120, 135, 150, 165. What does =INDEX(B2:E5, MATCH("South",A2:A5,0), MATCH("Q3",B1:E1,0)) return?
Step 9 of 10Practice · True or false
VLOOKUP can return a value from a column to the left of the column it searches.
Step 10 of 10Practice · Choose one
You maintain a pricing file for colleagues who use Excel 2016. Product codes are in column D and prices in column B. Which formula should you use?
Lesson complete!