r/ExcelTips • u/ClickOk5811 • 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:
IFERRORcatches 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_foundonly 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
FALSEat 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
3
u/OnafridayR 14d ago
I'd love xlookup to incorporate an 'iffound' argument
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.
3
u/AngryCustomerService 15d ago
Excellent tip! Thank you.