Skip to content

When a lookup can't find a match

Exact lookups8 min

Builds on Look up a value with VLOOKUP, Replace an error with IFERROR and Tidy text with TRIM, CLEAN, UPPER and PROPER.

The purchasing team at a hardware wholesaler in Ohio looks up the supplier on every incoming invoice. Most lines come back with a name. A few show #N/A: one supplier is new to the list, one code was pasted with a space at the end, and one arrived from the accounting system as text.

How it works

An exact lookup compares the value you give it with every value in the search column, and it needs one that is the same character for character and of the same type. #N/A means "not available": none was.

Sometimes that's simply true, because the code isn't on the list yet. Then wrap the lookup in IFNA(value, value_if_na), which returns its second argument in place of #N/A and lets every other result through.

Often the value is on the list and only looks the same. To Excel, "BX-17 " with a space at the end is a different text from "BX-17", and the text "4021" that some exports produce is a different value from the number 4021. A message would hide those rows, so fix the value you look up, inside the lookup: TRIM removes spaces at the start and end, and VALUE turns text that looks like a number into a number.

Example

A gym's front desk scans each member's card, and the card number lands in D2. The member list has card numbers in A2:A6 and names in B2:B6.

=IFNA(VLOOKUP(D2,A2:B6,2,FALSE),"Card not found")
Looks up the card number in D2 in A2:A6 and returns the member's name from column B, or Card not found when the number isn't on the list.

A card on the list shows the member's name, and a new card shows Card not found.

The same digits and the same lookup. The numbers in column A never match the text 1042, so the first lookup finds nothing. D2 holds the text 1042: in D3, =VLOOKUP(D2,A2:B6,2,FALSE) returns #N/A. D2 holds the number 1042: in D3, =VLOOKUP(D2,A2:B6,2,FALSE) returns Marcus Webb.

Common mistakes

  • Inside IFERROR, a typo such as VLOOKUP(D2,A2:B6,3,FALSE), which asks for a 3rd column the table doesn't have, makes every card look unknown: VLOOKUP shows #REF! and IFERROR hides it. IFNA lets that error show.
  • A code you can see still shows #N/A: compare =LEN(D2) with the number of characters you expect, and a longer result means hidden spaces. Look up TRIM(D2).
  • A number stored as text sits on the left of its cell, often with a small green triangle in the corner. Look up VALUE(D2), or when it's the list that holds text, look up D2&"".

In short

  • #N/A from an exact lookup means nothing in the list is the same value: the same characters and the same type.
  • =IFNA(lookup, "message") replaces only #N/A, so mistakes in the formula still show.
  • Clean the value you look up, inside the lookup: TRIM for spaces, VALUE for numbers stored as text.

Practice

4 exercises · free, no account needed

Start practicing
  1. Not started

    1. Price, or not on the list

    Formula · easy

  2. Not started

    2. An account number with extra spaces

    Formula · medium

  3. Not started

    3. A staff number stored as text

    Formula · medium

  4. Not started

    4. Why a lookup shows #N/A

    Quiz · easy