A missing code gets a message. Look up the code in A5.
AB
1CodeName
2P110Item A
3P245Item B
4P390Item C
5P999

In B5, write =XLOOKUP(A5,$A$2:$A$4,$B$2:$B$4,"Not listed") and it shows Not listed.

What is different

XLOOKUP(lookup_value, lookup_range, return_range, if_not_found, match_mode, search_mode) names the column to search and the column to return, so there is no column number to count and the answer can be to the left of the key.

It matches exactly unless you ask otherwise. The fourth argument is returned when nothing matches, so an IFERROR wrapper is not needed. A match mode of -1 returns an exact match or the next smaller item, which is how you do a band lookup without sorting.

When to use VLOOKUP anyway

Some workbooks and some tests are opened in programs that do not have XLOOKUP, and VLOOKUP is understood by everyone. If a task says to use a lookup function without naming one, VLOOKUP, XLOOKUP and INDEX with MATCH are all accepted.

Not found

Both give #N/A for a missing value. VLOOKUP needs IFERROR to replace it, while XLOOKUP takes the replacement as its fourth argument, and an empty text there gives a blank cell.

Practise it

Module 3, Lookups, has 20 tasks on this, each checked on hidden data: open module 3. You can also try formulas in the sandbox.

Related guides