Remove #N/A in vlookup result
Asked Answered
B

4

55

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!

Bergeron answered 7/1, 2013 at 20:9 Comment(0)
L
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))

Languishment answered 7/1, 2013 at 20:14 Comment(2)
That did it! I'm using Excel 2003 so that last line did the trick. Thank you :)Bergeron
Yep, IFERROR is what I needed to. IF just wasn't cuttin' it!Eveevection
J
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.

Jinx answered 31/7, 2014 at 14:48 Comment(0)
R
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.
Rutledge answered 28/9, 2022 at 15:33 Comment(0)
M
-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

Mcbrayer answered 15/3, 2014 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.