XLOOKUP, VLOOKUP and Fixing Errors
Pull matching values from another table with XLOOKUP and VLOOKUP, understand exact matches, and read and fix errors like #N/A, #REF! and #DIV/0!.
Welcome back!
Step 1 of 10Learn
The two-table problem
Jamal has an orders sheet listing a product code in each row, such as P-104, and a separate price list tab with codes in column A and prices in column C. For each order he needs the price. Copying prices by hand from one tab to the other is slow and goes wrong the moment a price changes.
This is a lookup: find a value in one list and return the matching value from another column. It's one of the most useful skills in spreadsheets.
Google Sheets has XLOOKUP:
=XLOOKUP(search_key, lookup_range, result_range, [missing_value])
In plain words: find this, in this column, and give me the value from that column. For Jamal:
=XLOOKUP(B2, Prices!A2:A200, Prices!C2:C200, "Not found")
- B2 is the product code on the order.
- Prices!A2:A200 is the column of codes on the Prices tab. (Sheet name, exclamation mark, range.)
- Prices!C2:C200 is the column of prices to return.
- "Not found" is shown if the code doesn't exist, instead of an error.
XLOOKUP looks for an exact match by default, which is what you want for codes, emails and IDs. The lookup and result ranges must be the same size. And because they're separate arguments, the result column can be to the left or right of the lookup column.
When copying this formula down, lock the ranges with dollar signs (Prices!$A$2:$A$200) so they don't shift.
Step 2 of 10Practice · Choose one
Which formula returns the email address (column D) for the employee ID in G2, where IDs are in column A of the same sheet, rows 2–500?
Step 3 of 10Learn
VLOOKUP: the older cousin
You'll meet VLOOKUP in many existing spreadsheets, so it's worth knowing how to read it:
=VLOOKUP(search_key, range, index, is_sorted)
- search_key: the value to find.
- range: a block of columns. VLOOKUP always searches the first (leftmost) column of this block.
- index: which column of the block to return, counting from 1.
- is_sorted: use FALSE for an exact match.
Jamal's lookup with VLOOKUP would be =VLOOKUP(B2, Prices!A2:C200, 3, FALSE): find B2 in column A of the block and return the 3rd column, C.
Two traps make VLOOKUP error-prone:
- Forgetting FALSE. If the last argument is missing or TRUE, VLOOKUP assumes the first column is sorted and returns the closest match below the value. For product codes, that silently returns a wrong price instead of an error, the most dangerous kind of mistake.
- The fixed column number. If someone inserts a new column into the price list, the price moves to column 4, but the formula still says 3 and now returns the wrong field.
VLOOKUP also can't look to the left: the return column must be to the right of the search column. XLOOKUP avoids all three problems, so prefer it for new work, and use VLOOKUP when you must share files with people on very old spreadsheet software.
Step 4 of 10Practice · True or false
VLOOKUP(B2, A2:C100, 3) without a fourth argument always looks for an exact match.
Step 5 of 10Compare
XLOOKUP vs. VLOOKUP
| Aspect | XLOOKUP | VLOOKUP |
|---|---|---|
| Default match | Exact | Approximate unless the last argument is FALSE |
| Where the result can be | Any column, left or right | Only to the right of the search column |
| Someone inserts a column | Still correct: ranges adjust | Fixed index may now return the wrong field |
| Value not found | Optional built-in fallback text | #N/A unless wrapped in IFERROR |
| When to use | New work in Google Sheets | Reading older files, sharing with very old software |
Step 6 of 10Learn
Reading error messages
Errors look alarming, but each one tells you what went wrong:
| Error | Meaning | Typical cause |
|---|---|---|
| #N/A | Value not available | A lookup could not find the search key |
| #DIV/0! | Division by zero | Dividing by an empty or zero cell |
| #REF! | Invalid reference | The formula points to a deleted cell, row or column |
| #NAME? | Unknown name | A misspelled function (=SUMM) or text missing quotes |
| #VALUE! | Wrong type of value | Doing math with text, such as ="ten"*2 |
| #ERROR! | Formula can't be parsed | Missing parenthesis or a stray character |
Hover over the cell, or click it, to see a short explanation from Sheets.
#N/A from a lookup usually means the value really isn't there, or it's there but different: an extra space ("P-104 "), a number stored as text, or a different spelling. The TRIM function, which you'll meet in the next lesson, removes stray spaces.
When an error is expected and harmless, such as a lookup for a code that hasn't been added yet, IFERROR shows something friendlier:
=IFERROR(B2/C2, 0) or =IFERROR(VLOOKUP(B2, A:C, 3, FALSE), "Check code")
Use IFERROR carefully. It hides every error, including real mistakes like a misspelled function or a deleted range. Fix the cause first; add IFERROR only for errors you understand and expect.
Step 7 of 10Practice · Match the pairs
Match each error with its most likely cause.
Tap an answer, then tap the place where it belongs (or drag it there).
- #N/A
- #DIV/0!
- #REF!
- #NAME?
- #VALUE!
Step 8 of 10Note
Step 9 of 10Practice · What would you do?
What would you do?
Your XLOOKUP for customer ID 10452 returns #N/A, but you can see 10452 in the customer list. The list was pasted in from another system, and its IDs sit on the left side of their cells while your IDs sit on the right. What is the most likely cause?
Step 10 of 10Practice · Choose one
Which VLOOKUP returns the value from the 4th column of A2:E300 for an exact match of the name in H2?
Lesson complete!