Sub topic 2
Common Errors and Data-Type Pitfalls in XLOOKUP
Assume you can enter and copy Excel formulas and understand ranges, relative references, and absolute references such as $E$2. The examples use Excel for Microsoft 365, Excel 2021, or Excel for the web.
Common errors and data types
#N/A means XLOOKUP found no match. Add the fourth argument to show a useful result:
=XLOOKUP(E2, A2:A10, C2:C10, "Not found")#VALUE! often means the lookup and return arrays have incompatible sizes. For example, A2:A10 contains nine cells, so the return range must also contain nine rows. Check that both ranges start and end on matching rows.
Data can look identical while having different types. The number 123 and the text "123" may not match. Dates can have the same issue when one cell contains a real date number and another contains text. Extra spaces also prevent exact matches. Use TRIM for ordinary spaces, and convert text numbers when necessary.
A successful lookup can still produce #SPILL! when a multi-column result has no empty cells beside the formula.
caption: How XLOOKUP errors are diagnosed
alt: A flowchart showing checks for a missing value, mismatched ranges, and blocked spill results.
flowchart TD
A[Formula returns an error] --> B{Which error?}
B -->|N/A| C[Check the lookup value and data type]
B -->|VALUE!| D[Check array dimensions]
B -->|SPILL!| E[Clear cells in the result area]Returning several columns at once
The return array can contain multiple columns. Excel spills the matching row into adjacent cells:
=XLOOKUP(E2, A2:A10, B2:D10)If the matching item is in row 5, this returns the values from B5, C5, and D5. Leave the required cells empty so the result can spill.
Choosing a `match_mode`
The fifth argument controls how XLOOKUP matches values.
| `match_mode` | Behavior | Typical use |
|---|---|---|
| `0` | Exact match; default | Product or employee ID |
| `-1` | Exact or next smaller item | Grade or rate bands |
| `1` | Exact or next larger item | Upper-limit bands |
| `2` | Wildcard match | Partial text |
For a tiered grade table with lower bounds in E2:E6, use:
=XLOOKUP(B2, $E$2:$E$6, $F$2:$F$6, "Below minimum", -1)For partial text, * means any number of characters:
=XLOOKUP("*"&E2&"*", A2:A10, C2:C10, "No match", 2)Exercise
What is the likely cause if =XLOOKUP(E2,A2:A10,B2:B8) returns #VALUE!?
Show answer
The lookup and return ranges have different numbers of rows.