Sub topic 5
Common errors and data-type pitfalls
This chapter assumes you can write a basic XLOOKUP and copy it down a column. You should also know absolute references such as $E$2 and have Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. Most XLOOKUP problems fall into two groups: a visible error value, and a wrong or missing result with no error at all. The second group is harder to spot, so most of this chapter is about it.
Reading the error value
Excel tells you what failed through the error code. Start with the code before you change anything.
| Error | Typical cause in XLOOKUP | First check |
|---|---|---|
| `#N/A` | No match was found | Does the value really exist? Do the data types agree? |
| `#VALUE!` | Mismatched or two-dimensional arrays, or an invalid mode argument | Compare the sizes of the lookup and return ranges |
| `#REF!` | A referenced cell or range was deleted, or a closed workbook is referenced | Look for `#REF!` inside the formula text |
| `#SPILL!` | A multi-cell result has no clear space to land | Clear the cells to the right or below |
| `#NAME?` | The function is unavailable or misspelled | Check your Excel version and the spelling |
#N/A: the value was not found
#N/A means "not available". For XLOOKUP, it usually means no entry in the lookup array equals the lookup value. Sometimes the value truly is missing. More often the two values look identical but Excel sees them as different.
Numbers stored as text
A number and the same digits stored as text are different values to XLOOKUP. The ID 1001 in one column will not match "1001" in another. Text values usually show a green triangle in the corner of the cell and align left by default. Do not rely on alignment, because it can be formatted away.
Test the two sides directly:
=ISNUMBER(E2)=ISNUMBER(A2)If the lookup value is text but the keys are numbers, convert the lookup value:
=XLOOKUP(VALUE(E2), A2:A10, C2:C10, "Not found")If the lookup value is a number but the keys are text, convert it to text by joining it with an empty string:
=XLOOKUP(E2&"", A2:A10, C2:C10, "Not found")Converting the lookup value inside the formula is quick. Converting the source column once, for example with Text to Columns or a helper column, is better when many formulas use it.
Extra spaces and invisible characters
Data pasted from web pages, exports, or other systems often has leading or trailing spaces. "Smith" and "Smith " are different values. The TRIM function removes extra spaces:
=XLOOKUP(TRIM(E2), A2:A10, C2:C10, "Not found")TRIM does not remove the non-breaking space, which is character code 160. Web data often contains it. Replace it with a normal space first:
=XLOOKUP(TRIM(SUBSTITUTE(E2, CHAR(160), " ")), A2:A10, C2:C10, "Not found")This cleans only the lookup value. If the spaces are in the lookup array, you need to clean that column instead, with a helper column or by fixing the source data.
To check whether a cell has hidden characters, compare its visible length with what you expect:
=LEN(E2)If "Smith" reports a length of 6, one character is hidden.
Decimals and dates
Exact matching works on the stored value, not the displayed one. A cell showing 12.35 might hold 12.3500000001 after a calculation. Rounding the lookup value, and the keys if they are computed, avoids this:
=XLOOKUP(ROUND(E2, 2), A2:A10, C2:C10, "Not found")Dates have the same problem. A date is a whole number, and a date with a time is a fraction added to it. A timestamp of 2026-11-27 09:30 will not exactly match the date 2026-11-27. Use INT(E2) to drop the time portion. Dates typed as text, such as "27/11/2026", behave like text numbers and need DATEVALUE or a clean source.
Ranges that drift when copied
Suppose you write this in row 2:
=XLOOKUP(E2, A2:A10, C2:C10)You then copy it down. In row 3 the ranges become A3:A11 and C3:C11, and the lookup range keeps sliding. Rows near the top of the table drop out of the search, so later lookups fail with #N/A. The fix is to anchor the ranges:
=XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10)If the formulas work in the first row and fail further down, suspect this first.
Wildcard characters in the data
With the default exact match (match_mode 0), the characters *, ? and ~ are ordinary text. When you set match_mode to 2, they become wildcards. A part code like AB*7 would then match any code beginning with AB and ending in 7. To search for a literal asterisk or question mark in that mode, put a tilde in front of it:
=XLOOKUP(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E2, "~", "~~"), "*", "~*"), "?", "~?"), A2:A10, C2:C10, "No match", 2)The tilde is replaced first so that the escapes added afterward are not escaped again.
#VALUE!: the arguments do not fit together
#VALUE! points to a problem with how the arguments are shaped, not with the data. These are the usual causes:
- The lookup array and the return array have different sizes. When the lookup array is a column of 9 rows, the return array must also have 9 rows.
A2:A10withC2:C11fails. - The lookup array is two-dimensional. It must be a single row or a single column.
A2:B10as the first range fails. - A mode argument is not an allowed number.
match_modeaccepts -1, 0, 1 and 2.search_modeaccepts 1, -1, 2 and -2. - A row and a column are mixed. A row lookup array such as
B1:E1needs a return array with the same number of columns, such asB2:E2.
The last case is easy to get wrong when you build a two-way lookup. In XLOOKUP(G2, B1:E1, B2:E6), the lookup array is a row of four cells. The return array is a block with four columns and five rows. That shape is valid, because the return array matches the lookup array in columns and the extra rows are returned together.
#SPILL!, #NAME? and #REF!
When the return array has several columns, as in =XLOOKUP(E2, A2:A10, B2:D10), the result spills into neighboring cells. If any cell in that area holds data, Excel shows #SPILL!. Clear the blocking cells and the result appears. Merged cells and Excel Tables also cause #SPILL!, because tables do not accept spilled results.
#NAME? has two causes. A misspelled function name is the simple one. The other is a version problem. Excel 2016 and 2019 do not include XLOOKUP, so a workbook created in Microsoft 365 can show #NAME? there.
#REF! appears when you delete a column or row that a formula used. It can also appear when a formula refers to a closed workbook that has moved or been renamed. Open the cell and look for #REF! in the formula text. Repair the reference there.
Results that are wrong without an error
Silent failures cost the most, because nothing warns you.
Duplicates return the first match
XLOOKUP returns the first match it finds. If an employee ID appears twice, you get the first row's data. To get the last match, set search_mode to -1:
=XLOOKUP(E2, $A$2:$A$100, $C$2:$C$100, "None", 0, -1)Use COUNTIF to check whether keys are unique before trusting a lookup:
=COUNTIF($A$2:$A$100, E2)Case is ignored
XLOOKUP treats "abc" and "ABC" as equal. When case matters, compare with EXACT, which returns an array of TRUE and FALSE values, and look for the first TRUE:
=XLOOKUP(TRUE, EXACT(E2, $A$2:$A$100), $C$2:$C$100, "Not found")Blank return cells show 0
If the matched row has an empty cell in the return column, XLOOKUP shows 0, not blank. Joining the result with an empty string turns it into text, so an empty cell appears empty:
=XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10, "Not found")&""The trade-off is that numeric results become text, so you cannot use them directly in calculations.
Binary search on unsorted data
Search modes 2 and -2 use a binary search. This needs ascending data for mode 2 and descending data for mode -2. If the data is out of order, Excel does not warn you. It returns wrong results, or #N/A for values that exist. Use binary search only on data you know is sorted. If you are unsure, use the default linear search.
A custom message hides real problems
The if_not_found argument replaces only the "no match" #N/A. It does not catch #VALUE! or #REF!, which is useful, because those show real problems. Wrapping the whole formula in IFERROR hides every error, including a broken range. A "Not found" message that appears on every row is a sign that something systematic is wrong, such as a data-type mismatch. Test with if_not_found left out while you debug, then add it back when the formula works.
Exercise
A lookup in cell F2 uses =XLOOKUP(E2, A2:A10, C2:C10, "Not found"). IDs in column A are numbers. The value in E2 is 1004 aligned to the left, and the formula returns "Not found". Give two quick checks to confirm the cause and one formula that fixes it.
Show answer
Check =ISNUMBER(E2), which returns FALSE if E2 is text, and =ISNUMBER(A2), which returns TRUE. Checking =LEN(E2) also helps: a length greater than 4 means hidden spaces. The fix is to convert the lookup value: =XLOOKUP(VALUE(E2), A2:A10, C2:C10, "Not found"). If spaces are the problem, use VALUE(TRIM(E2)).
Exercise
You copy =XLOOKUP(E2, A2:A10, C2:C10) down 20 rows. The first few rows work, but later rows return #N/A even though the IDs exist in the table. What went wrong and how do you fix it?
Show answer
The ranges are relative, so they shift down by one row with each copy and the table slides away from the lookup values. Anchor the ranges with absolute references: =XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10).
Exercise
=XLOOKUP(E2, A2:A10, C2:C11) returns #VALUE!. Why?
Show answer
The lookup array has 9 rows and the return array has 10 rows. The two arrays must be the same size. Change the return array to C2:C10.