54

How do I modify this function so that the result will merely be a blank cell rather than having #N/A show up if B2 has nothing in that cell?

I think I might need something like an ISERROR check but I don't 100% know what I'm doing.

=VLOOKUP(B2,Index!A1:B12,2,FALSE)

Thanks!

pnuts
  • 58,317
  • 11
  • 87
  • 139
office-rat
  • 575
  • 2
  • 5
  • 7

4 Answers4

111

If you only want to return a blank when B2 is blank you can use an additional IF function for that scenario specifically, i.e.

=IF(B2="","",VLOOKUP(B2,Index!A1:B12,2,FALSE))

or to return a blank with any error from the VLOOKUP (e.g. including if B2 is populated but that value isn't found by the VLOOKUP) you can use IFERROR function if you have Excel 2007 or later, i.e.

=IFERROR(VLOOKUP(B2,Index!A1:B12,2,FALSE),"")

in earlier versions you need to repeat the VLOOKUP, e.g.

=IF(ISNA(VLOOKUP(B2,Index!A1:B12,2,FALSE)),"",VLOOKUP(B2,Index!A1:B12,2,FALSE))

barry houdini
  • 45,615
  • 8
  • 63
  • 81
1

if you are looking to change the colour of the cell in case of vlookup error then go for conditional formatting . To do this go the "CONDITIONAL FORMATTING" > "NEW RULE". In this choose the "Select the rule type" = "Format only cells that contains" . After this the window below changes , in which choose "Error" in the first drop-down .After this proceed accordingly.

0

New Answer 9/28/2022

Here a new approach considering the new Excel function: XLOOKUP

=XLOOKUP(D2,$A$2:$A$5,$B$2:$B$5,"Not Found",0)

The third argument indicates the value to use in case of not found, you can replace it with "" in case you want to leave the cell empty.

sample excel file

Check the following additional resources for more information about this new function:

  1. XLOOKUP vs VLOOKUP: Which Excel Function Is Better?. It is more flexible than VLOOKUP, you can specify lookup_array and lookup_result ranges.
  2. Performance of XLOOKUP: How fast is the new XLOOKUP vs. VLOOKUP?:it seems some concern about XLOOKUP performance. Something to watch.
David Leal
  • 6,373
  • 4
  • 29
  • 56
-1

To avoid errors in any excel function, use the Error Handling functions that start with IS* in Excel. Embed your function with these error handing functions and avoid the undesirable text in your results. More info in OfficeTricks Page

KumaraPush
  • 51
  • 3