Lookup: Validate A Code Exists Before Using It Downstream (ISNA Guard)

Excel Formulas › Lookup

All versions

A typo in a product code or customer ID does not just break one lookup — it breaks every downstream formula that depends on that lookup succeeding, often several sheets away from where the typo actually happened. Validating the code right where it is typed, before any XLOOKUP or VLOOKUP runs against it, turns a confusing #N/A buried in a summary tab into a clear message at the point of entry.


Quick formula: MATCH tries to find the code in the reference list; ISNA checks whether that search failed:
=IF(ISNA(MATCH(A2,$D$2:$D$8,0)),"Not found — check the code","OK")

A code that exists in the list returns OK; a mistyped one is flagged immediately, before any price or inventory lookup runs against it.

Functions used (tap for the full reference guide):

The example

Four codes typed into an order form; one (SKU-4041) does not exist in the product list because of a transposed digit.

AB
1Typed codeValidation
2SKU-1001OK
3SKU-2044OK
4SKU-4041Not found — check the code
5SKU-3390OK

The formula

MATCH either returns a position (success) or the #N/A error (failure); ISNA turns that into a checkable TRUE/FALSE:

=IF(ISNA(MATCH(A2,$D$2:$D$8,0)),"Not found — check the code","OK") // ISNA catches a failed MATCH before it becomes a visible #N/A

How it works

Working from the inside out:

  1. MATCH(A2,$D$2:$D$8,0) searches for this row's typed code in the reference list. The 0 forces an exact match. If found, it returns the code's position in the list; if not found, MATCH itself returns the #N/A error.
  2. ISNA(...) wraps that result and returns TRUE if MATCH errored (code not found) or FALSE if MATCH succeeded (code found) — ISNA is built specifically to test for the #N/A error and nothing else.
  3. IF(ISNA(...),"Not found...","OK") turns that TRUE/FALSE into a human-readable message, catching the problem right in the row where the code was typed.

Chain every downstream lookup (price, description, stock level) behind this validation column with an IF, so they only attempt to run once the code has already passed the ISNA guard.

Try it: interactive demo

Interactive

Type a code and see whether it exists in the sample reference list (SKU-1001, SKU-2044, SKU-3390).

Variations

Use IFERROR for a shorter version when you only care that it failed

IFERROR catches ANY error (not just #N/A), which is fine here since MATCH with these arguments cannot realistically raise a different error type, and it is a shorter formula.

=IFERROR("OK","Not found — check the code")

Highlight invalid codes directly with conditional formatting

Use the same ISNA(MATCH(...)) test as a conditional formatting rule on the typed-code cell itself, so an invalid entry turns red the moment it is typed, with no separate validation column needed.

=ISNA(MATCH($A2,$D$2:$D$8,0))

Pitfalls & errors

ISNA only catches the #N/A error specifically. If the underlying MATCH could fail for a different reason (a #REF! from a deleted reference range, for instance), ISNA will not catch it and the error will still show. IFERROR catches every error type if that broader net is what you actually want.

Do the validation on a raw typed value BEFORE any TRIM or UPPER cleanup is applied, in a separate check, if you also want to know whether the user's exact input matched — cleaning the input first will make a code with stray spaces silently pass validation, which may or may not be what you want.

The third argument to MATCH must be 0 for an exact match. Leaving it out defaults to an approximate match (1), which requires the reference list to be sorted ascending and can return a false OK for a code that does not actually exist but happens to sort near one that does.

Practice workbook

📊
Download the free Lookup: Validate A Code Exists Before Using It Downstream (ISNA Guard) practice workbook
Edit the yellow typed-code cells (try a code not in the reference list); validation recalculates. Column C holds the reference code list the formula checks against.

Frequently asked questions

Is this different from data validation (the dropdown list feature)?
Yes — Excel's Data Validation feature restricts what a user CAN type into a cell in the first place, which is a great first line of defense but does not help with data that arrives already typed (a paste, an import, a formula result). This ISNA/MATCH check validates data no matter how it got into the cell.
Can I use this with XLOOKUP's built-in if_not_found argument instead?
Yes, if the only thing you need is a graceful fallback value for one specific lookup — XLOOKUP's fourth argument handles that in a single function. This ISNA/MATCH pattern is more useful when you want a SEPARATE validation flag to gate several different downstream lookups off the same one check.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: XLOOKUP with an 'If Not Found' Default · Error-Proof a Model with IFERROR · Find Values Not in an Allowed List

Function references: ISNAMATCH