Suppress #N/A returned by Google Sheets vlookup

前端 未结 3 1729
天命终不由人
天命终不由人 2021-02-06 21:22

I have a Google Sheet (example) with a basic vlookup to create a summable column. It returns \"#N/A\" for every search key not found, and attaches the following error to those c

相关标签:
3条回答
  • 2021-02-06 22:00

    =IFNA(VLOOKUP(...), "")

    Not sure if this has changed recently, but the IFNA implementation supports a single listing of the VLOOKUP now. That is, you don't have to wrap it in another IF.

    An advantage there is that you could choose "", 0, NULL, etc. as the value to show on failure.

    0 讨论(0)
  • 2021-02-06 22:01

    Update 2019-03-01: The best solution is now =IFNA(VLOOKUP(…), 0). See this other answer.

     

    You can use the following formula. It will replace the #N/A values returned by VLOOKUP(…) with 0.

    =SUMIF(VLOOKUP(…),"<>#N/A")
    

    How it works: This uses SUMIF() with only one value to sum up. So the result is that one value – if unequal to #N/A, according to the condition. If the value is #N/A however, the sum is zero. That's just how SUMIF() works: if no values match the conditions, the result is 0, not NULL, not #N/A.

    Advantages:

    • Compared to the solution =IF(ISNA(VLOOKUP(…)),"",VLOOKUP(…)) referenced in the question, this solution contains the VLOOKUP(…) part only once. This makes the formula shorter and simpler, and avoids the mistakes that happen when editing only one of the two VLOOKUP(…) parts.

    • Compared to the solution =IFERROR(VLOOKUP(…)) from the other answer, errors are not suppressed as that would make detecting and debugging them more difficult. Only #N/A values are suppressed.

    0 讨论(0)
  • 2021-02-06 22:04

    A simpler way to suppress error messages - of any kind - is to use the iferror wrapper:

    =iferror(vlookup(A1,Lookup!A:B,2,FALSE))
    

    I don't think there can be an easier way than that. By design, vlookup should not simply return blank if the key wasn't found: this would be indistinguishable from the situation where the key was found but the corresponding entry in second column was blank. Some error has to be thrown, and then it's up to the spreadsheet user how to handle it.

    0 讨论(0)
提交回复
热议问题