Sub topic 3
Exact match: the default behavior
This chapter explains what XLOOKUP does when you give it only three arguments. It covers how the exact match works, which edge cases decide whether it finds your value, and how to read the result. It assumes you can enter and copy formulas, that you understand ranges and absolute references such as $E$2, and that you have Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. The earlier chapters introduced the six arguments. This one uses only the first three.
The sample data
All examples use this table in A1:C10. The lookup value is typed in E2.
| Cell range | A: Employee ID | B: Name | C: Department |
|---|---|---|---|
| Row 2 | 101 | Ana Silva | Sales |
| Row 3 | 102 | Ben Okafor | Finance |
| Row 4 | 103 | Chen Wei | Sales |
| Row 5 | 104 | Dara Nolan | Support |
| Row 6 | 105 | Eli Park | Finance |
| Row 7 | 106 | Fay Moreau | Legal |
| Row 8 | 107 | Gus Lindqvist | Support |
| Row 9 | 108 | Hana Ito | Sales |
| Row 10 | 109 | Ivo Petrov | Legal |
The default is an exact match
When you leave out the fourth, fifth and sixth arguments, XLOOKUP uses these defaults:
if_not_found: none, so a missing value produces#N/A.match_mode:0, which means exact match.search_mode:1, which means search from first to last.
This formula looks up the ID in E2 and returns the department:
=XLOOKUP(E2, A2:A10, C2:C10)If E2 contains 104, the formula returns Support. If E2 contains 999, no cell in A2:A10 equals 999, so the formula returns #N/A.
You can write the defaults out explicitly. The empty fourth argument keeps the default #N/A behavior:
=XLOOKUP(E2, A2:A10, C2:C10, , 0, 1)This formula behaves exactly like the three-argument version. Writing the defaults is useful when you want a reader to see that exact matching is intentional. It also makes it clear which argument to change later.
How the lookup works internally
The formula works in two steps:
- Excel scans
lookup_arrayand finds the position of the first cell equal to the lookup value. For 104 that position is 4, because104is the fourth item inA2:A10. - Excel returns the item at that same position in
return_array. The fourth item inC2:C10isSupport.
The two ranges are never compared to each other. Only the lookup array is searched. The return array is read by position.
Because the search is positional, the return array can sit anywhere. It can be to the left or right of the lookup array, or even on another sheet. This is a major difference from VLOOKUP, which can only return values from columns to the right of the lookup column.
Rules for the two arrays
The lookup array and the return array must line up item for item:
- Both must be a single column, or both a single row, in the orientation you are searching.
- They must have the same number of items.
- They do not need to be adjacent or the same width.
This formula fails because A2:A10 has nine rows and C2:C11 has ten:
=XLOOKUP(E2, A2:A10, C2:C11)Excel returns #VALUE! because the positions no longer correspond. Copying a formula down can create this mismatch if only one range is anchored. Lock both ranges with absolute references:
=XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10)A lookup also works across a row. If quarter labels are in B1:E1 and sales totals are in B2:E2, this formula returns the total for the quarter named in G1:
=XLOOKUP(G1, B1:E1, B2:E2)Whole-column references also work, which suits tables that grow:
=XLOOKUP(E2, A:A, C:C)Whole-column references are convenient. They also include the header cell, so a lookup for the text "Employee ID" would match row 1. If your data is in an Excel Table, structured references such as Employees[ID] grow with the data and avoid this problem.
What counts as "equal"
Exact matching is stricter than it looks. These rules explain most "the value is there but XLOOKUP cannot find it" problems.
Case is ignored
Text comparison is not case sensitive. A lookup for ana silva matches Ana Silva:
=XLOOKUP("ana silva", B2:B10, A2:A10)This returns 101. If you need a case-sensitive match, XLOOKUP cannot do it directly. You would need to build a test with the EXACT function, which is outside this chapter.
Spaces count
A cell containing "Ana Silva " with a trailing space is not equal to "Ana Silva". Extra spaces often arrive with data pasted from other systems. You can clean the lookup value without changing the source:
=XLOOKUP(TRIM(E2), A2:A10, C2:C10)TRIM removes leading and trailing spaces and collapses repeated spaces inside the text. It cannot fix trailing spaces in A2:A10 itself. Clean those cells with a helper column, or use TRIM on the lookup array inside the formula.
Numbers and text are different types
The number 102 and the text "102" look the same in a cell but do not match. This usually happens when IDs are imported from a CSV file or typed with a leading apostrophe. The cell may show a small green triangle, and a text value is left-aligned by default.
If the lookup value is text but the array holds numbers, convert the lookup value:
=XLOOKUP(VALUE(E2), A2:A10, C2:C10)If it is the other way around, join an empty string to turn the number into text:
=XLOOKUP(E2&"", A2:A10, C2:C10)Check what type each side has before you choose. A quick way is =ISNUMBER(E2), which returns TRUE for a number and FALSE for text.
Wildcard characters are literal
In exact mode, * and ? have no special meaning. A lookup for "Sal*" searches for the literal text Sal*. It does not find Sales. This differs from VLOOKUP and MATCH with exact matching, which treat those characters as wildcards. Wildcard matching in XLOOKUP is a separate option, covered in a later chapter.
Calculated numbers can differ slightly
A value produced by arithmetic, such as a price after a discount, can differ from a typed number in a far decimal place, so it may not match. If you look up calculated numbers, round both sides to the same number of decimals with ROUND before comparing.
Duplicates: the first match wins
If a lookup value appears more than once, XLOOKUP returns the result for the first one it finds when searching from the top. Suppose a second row used ID 104. The formula would return the department from the earlier row and ignore the later one, with no warning.
This matters for tables where the key should be unique but is not. To check, count how many times the key appears:
=COUNTIF(A2:A10, E2)A result greater than 1 means a duplicate exists. If you want the last match instead of the first, change search_mode to -1. That option is covered in a later chapter.
Reading the result
| Result | What it usually means |
|---|---|
| A value from the return array | An exact match was found. |
| `#N/A` | No cell in the lookup array equals the lookup value. |
| `#VALUE!` | The arrays have different sizes or the wrong shape. |
| `#REF!` | A referenced range was deleted, or the workbook link is broken. |
| A blank-looking cell showing `0` | The match was found, but the matching return cell is empty. |
The last row is a common surprise. If the matched return cell is empty, XLOOKUP returns 0, not an empty result. If you need a blank, use a formula such as this:
=XLOOKUP(E2, A2:A10, C2:C10)&""Joining an empty string converts the result to text, so an empty return cell shows as blank. The side effect is that numeric results also become text, so only use this when the result is for display.
When #N/A is the right answer
#N/A is not always a problem to hide. In a reconciliation, an #N/A tells you a key is missing from the other list, which can be exactly what you want to find. The next chapter shows how to replace it with a message when a clean display matters more than a visible error. Decide per sheet. If other formulas depend on the result, a visible error is safer than a text placeholder that might be silently treated as data.
Exercises
Exercise
A table has employee IDs in A2:A10 and names in B2:B10. Write an exact-match formula that returns the name for the ID typed in E2. Then explain what happens when E2 holds the text "105" while the IDs in column A are real numbers.
Show answer
=XLOOKUP(E2, A2:A10, B2:B10). If E2 holds the text "105" and column A holds the number 105, the formula returns #N/A, because exact matching treats text and numbers as different types. Convert the lookup value with VALUE(E2), as in =XLOOKUP(VALUE(E2), A2:A10, B2:B10).
Exercise
A formula uses =XLOOKUP(E2, A2:A10, C2:C11) and returns #VALUE!. What is the cause, and how do you fix it?
Show answer
The lookup array has nine items (A2:A10) and the return array has ten (C2:C11), so positions do not correspond. Make both ranges the same size, for example =XLOOKUP(E2, A2:A10, C2:C10).
Exercise
The ID 104 appears in both row 5 and row 12 of the lookup column. With default settings, which row does =XLOOKUP(104, A2:A20, C2:C20) use, and which formula tells you how many times 104 appears?
Show answer
It uses row 5, the first match when searching from top to bottom. =COUNTIF(A2:A20, 104) returns the number of occurrences, here 2.