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 any #N/A value possibly returned by VLOOKUP(…) with 0.
=SUMIF(VLOOKUP(…),"<>#N/A")
How it works: This uses SUMIF() with only one value VLOOKUP(…) to sum up. So the result is that one value, but only if unequal to #N/A as per the condition argument. If the value equals #N/A however, the sum is zero. That’s just how SUMIF() works: if no values match the conditions, it returns 0, not NULL, not #N/A.
Advantages:
-
Compared to the solution
=IF(ISNA(VLOOKUP(…)),"",VLOOKUP(…))referenced in the question, this solution contains theVLOOKUP(…)part only once. This makes the formula shorter and simpler, and avoids the mistakes that happen when editing only one of the twoVLOOKUP(…)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/Avalues are suppressed.