r/ExcelTips • • 15d ago

Tip: use XLOOKUP’s 4th argument instead of wrapping lookups in IFERROR

If you’ve been writing =IFERROR(VLOOKUP(...), "Not found"), XLOOKUP has the “not found” message built in as its fourth argument.

Before:

=IFERROR(VLOOKUP(A2, Prices!A:B, 2, FALSE), "Not found")

After:

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

Syntax, for reference:

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Why it’s better than IFERROR:

  • IFERROR catches every error, not only “value not found”. A typo in a range, a #REF! from a deleted column, or a #VALUE! from bad data would all show up as “Not found”, and you’d never see the real problem.
  • if_not_found only handles the not-found case. Other errors still show, which is usually what you want.
  • It’s shorter, and you don’t have to repeat the lookup.

Two more small things in the same formula:

  • XLOOKUP does an exact match by default. VLOOKUP’s default is approximate match (which is why the FALSE at the end is so often needed).
  • You select the lookup column and the return column separately, so inserting a column in your table doesn’t shift a column index number like VLOOKUP’s 2.

Availability: XLOOKUP is in Excel 2021 and Microsoft 365 (and Excel for the web), but not in older versions like Excel 2019 and earlier. Check your version before sharing a file with someone who may use an older one, because the formula will show an error there.

89 Upvotes

11 comments sorted by

3

u/OnafridayR 14d ago

I'd love xlookup to incorporate an 'iffound' argument

5

u/myers_hertz 14d ago

I think you can just put the value you want in the return array parameter of the xlookup

=XLookup(A2, Prices!A:A, "Found", "Not Found")

2

u/OnafridayR 14d ago

WTF? Thanks so much

1

u/OnafridayR 12d ago

Doesn't seem to work for me

2

u/WildfireZ 13d ago

Wow, now that's an amazing tip!

1

u/SageofTurtles 14d ago

That would just be the return array?

2

u/Petrichordates 14d ago

Vlookup already outputs an N/A there, what's the point of adding an extra formula just to change that to Not Found?

The way bigger problem is that it outputs blanks as 0s.

1

u/DarkWingDingus 14d ago

This. I hate having to do workarounds for such a simple thing 

1

u/marmata75 12d ago

That enables you to do something else when not found. Like searching another table, or whatever other formula you need!

1

u/EvidenceHistorical55 8d ago

Good ol &"" at the end

3

u/AngryCustomerService 15d ago

Excellent tip! Thank you.