跳到正文
DEV Community· TidyGrid Studio·· 2 小時前AI 評分49

VLOOKUP 顯示 #N/A 但值明明存在:5 個原因及修正方法

VLOOKUP Returns N/A but the Value Is Right There: 5 Causes and Fixes

AI 導讀

Google Sheets 的 VLOOKUP 即使搜尋值明明存在,仍可能顯示 #N/A,常見原因包括隱藏空格、數字與文字格式不一致、搜尋範圍未從正確欄開始、缺少 FALSE 精確匹配,以及複製公式後範圍移位。文章提供相應檢查方法與公式,並建議用 IFNA 顯示「Not found」,避免 IFERROR 一併隱藏其他錯誤。

正文

This article was written with AI assistance. The formulas were tested in LibreOffice Calc; Sheets-specific messages and menus were checked against Google's help pages and common Sheets guides.

You type a VLOOKUP, the item is clearly sitting in the other table, and Google Sheets still says #N/A. Hover the cell and you get "Did not find value 'X' in VLOOKUP evaluation."

Sheets is not wrong. It is telling you that the two values are not exactly the same, or that it is looking in the wrong place. Here are the five causes I see most, in the order worth checking.

The examples use this setup: the value you look up is in A2, and the table you search is Prices!A:C (item names in column A, prices in column C).

1. An invisible space

"Apple " and "Apple" look identical on screen. To Sheets they are different text.

Check: in an empty cell, type =LEN(A2) and compare it with the number of characters you can see. One more than expected means a trailing space.

Fix: trim the value you look up.

=VLOOKUP(TRIM(A2), Prices!A:C, 3, FALSE)

If the spaces are in the table instead, clean that column once: put =ARRAYFORMULA(TRIM(Prices!A2:A)) in an empty column, then copy it and use Edit > Paste special > Values only over the original.

Data pasted from a website sometimes carries a non-breaking space, which looks like a space but is a different character. TRIM does not remove it. If TRIM does not help, swap it out first:

=VLOOKUP(TRIM(SUBSTITUTE(A2, UNICHAR(160), " ")), Prices!A:C, 3, FALSE)

UNICHAR(160) is the non-breaking space in Sheets, Excel and LibreOffice alike, so the same formula works if you move the file.

2. A number on one side, text on the other

Order IDs, ZIP codes and SKUs are the usual suspects. 1042 the number and "1042" the text are different values, and an exact-match lookup usually will not pair them.

Check: =ISNUMBER(A2) and =ISNUMBER(Prices!A2). If one says TRUE and the other FALSE, this is your problem. A quick visual hint: numbers sit on the right of the cell by default, text on the left.

Fix: convert the lookup value to match the table.

Table holds text, you have a number:

=VLOOKUP(A2&"", Prices!A:C, 3, FALSE)

Table holds numbers, you have text:

=VLOOKUP(VALUE(A2), Prices!A:C, 3, FALSE)

3. The value is not in the first column of the range

VLOOKUP only searches the first column of the range you give it. If you wrote Prices!B:D but the names live in column A, it searches the wrong column and finds nothing.

Fix: start the range at the column that holds what you are searching for. If the result you want sits to the left of that column, VLOOKUP cannot reach it. Use XLOOKUP instead. Say A2 holds a price and you want the item name: search column C, return column A.

=XLOOKUP(A2, Prices!C:C, Prices!A:A, "Not found")

4. The fourth argument is missing or TRUE

=VLOOKUP(A2, Prices!A:C, 3) leaves out the last argument. Sheets then assumes the first column is sorted and does an approximate search. On an unsorted list this can return #N/A even though the value exists, or worse, a wrong row with no error at all.

Fix: always end with FALSE for an exact match.

=VLOOKUP(A2, Prices!A:C, 3, FALSE)

5. The range moved when you copied the formula down

You wrote =VLOOKUP(A2, Prices!A2:C50, 3, FALSE) in row 2 and dragged it down. By row 10 it has become Prices!A10:C58, so items in rows 2 to 9 of the table are no longer searched. The same happens when the table grows past row 50.

Check: click a failing cell lower down and read the range in the formula bar.

Fix: lock the range with $, or use whole columns so new rows are included too.

=VLOOKUP(A2, Prices!$A$2:$C$500, 3, FALSE)
=VLOOKUP(A2, Prices!A:C, 3, FALSE)

When the value really is missing

Sometimes #N/A is the right answer: the item is not in the table. Show a clear message instead of an error, but use IFNA, not IFERROR. IFNA only hides "not found". IFERROR also hides real mistakes like a broken range, so you never find out.

=IFNA(VLOOKUP(TRIM(A2), Prices!A:C, 3, FALSE), "Not found")

Quick checklist

  1. =LEN(A2) longer than it looks? Use TRIM.
  2. ISNUMBER differs between the two sides? Convert with &"" or VALUE.
  3. Does the range start at the column you search?
  4. Does the formula end with FALSE?
  5. Did the range shift when copied down? Lock it with $.

If you want a few ready-made formulas for everyday sheet chores (totals by category, duplicate IDs, cleaning pasted prices), we put five of them in a free template pack: Formula Fix Kit.

來源:DEV Community · dev.to