Sub topic 12
Troubleshooting #N/A Results
This chapter assumes you can enter formulas in Google Sheets, use cell and range references, write absolute references such as $A$2:$C$100, and reference another sheet. You should also know the basic syntax of VLOOKUP and XLOOKUP.
The #N/A error means that a lookup did not find a matching value under its current rules. The most common causes are different text, different data types, an incorrect range, or an inappropriate match mode.
Check the search key first
Suppose A2:A100 contains product IDs and C2:C100 contains prices:
=XLOOKUP(E2, A2:A100, C2:C100)Start by comparing E2 with the value you expect to find. Look for:
- Leading or trailing spaces.
- Different capitalization when the data was created or transformed.
- A missing character or different punctuation.
- A nonprinting character copied from another system.
- A number stored as text in one location and as a number in the other.
A space is easy to miss. This formula removes leading and trailing spaces from the search key:
=VLOOKUP(TRIM(A2), Products!A2:C100, 3, FALSE)If the values in the lookup column also contain unwanted spaces, clean that column separately. TRIM does not automatically change every cell in the source range.
You can inspect a value with LEN. If two apparently identical IDs have different lengths, they contain different characters:
=LEN(E2)
=LEN(A2)For more difficult imported data, CLEAN can remove some nonprinting characters:
=TRIM(CLEAN(E2))Check numbers stored as text
The value 102 as a number is different from "102" as text for lookup purposes in many spreadsheet situations. A cell may look numeric while actually containing text.
Use ISNUMBER and ISTEXT to test the type:
=ISNUMBER(E2)
=ISTEXT(E2)If the key should be numeric, convert the search key:
=XLOOKUP(VALUE(E2), A2:A100, C2:C100, "Not found")Alternatively, convert a text key to text consistently:
=XLOOKUP(TO_TEXT(E2), A2:A100, C2:C100, "Not found")Choose one representation for the entire key column. Do not convert values blindly when leading zeros matter. For example, product code 00102 should remain text rather than becoming the number 102.
Check the match mode and sort order
An exact lookup should normally be explicit:
=VLOOKUP(E2, A2:C100, 3, FALSE)With VLOOKUP, FALSE requests an exact match. If you omit the last argument, Google Sheets uses approximate matching. Approximate matching expects the first column of the range to be sorted in ascending order. It can return an incorrect row when the data is unsorted, and it can return #N/A when the key is smaller than the first sorted value.
For a tier table, approximate matching is useful:
=VLOOKUP(B2, $F$2:$G$6, 2, TRUE)For ordinary IDs, use exact matching instead. With XLOOKUP, exact matching is the default:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")Make sure the lookup range and result range have compatible sizes. A lookup range of A2:A100 should not be paired with a result range that starts at a different row.
Show a useful message
After fixing the cause, decide how the sheet should display a genuinely missing key. XLOOKUP accepts a value for that case:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")With VLOOKUP, use IFNA:
=IFNA(VLOOKUP(E2, A2:C100, 3, FALSE), "Not found")Do not use an error wrapper to hide a broken range, misspelled key, or type mismatch during diagnosis. First confirm that a valid key returns the expected value. Then add the friendly message for normal use.
Exercise
An exact XLOOKUP returns #N/A, but the key looks identical to the source value. What should you check first?
Show answer
Compare the lengths and data types of the two cells. Use LEN to detect hidden spaces or characters, and ISNUMBER or ISTEXT to detect a number-versus-text mismatch. Clean or convert the values consistently, then test the lookup again.