You did not indicate you have an earlier version of Excel so probably patkim
's answer did the trick for you nicely. But for those with an earlier version, there are things that can be done.
A couple of easy ways come to mind.
If you wish the simplest way, you can "wrap" whole formula, as is, in a SUBSTITUTE()
function telling it to replace any occurrences of "space-comma" with nothing ("") or "space-comma-space" with a single "space".
So, like so:
=SUBSTITUTE( VLOOKUP(A1, A3:K20, 2, 0)&" ," & VLOOKUP(A1, A3:K20, 3, 0)&" ," & VLOOKUP(A1, A3:K20, 4, 0), " ,", ",")
(You have conflicting information between the formula, the picture, and your question's text. Two pieces seem to put a comma and nothing else between pieces while the other puts a "space-comma"... I've decided the picture controls the idea and changed the above to fit that. However, if one used simply the comma in the concatenation, then two or more missing data would lead to several commas in a row and only pairs of them would be handled but even then it's not "recursive" so one could still have multiple commas. Using "space-comma" in the concatenation gets around that problem.)
More complicated, but easy to do and arguably easier to understand when looking at the formula a year from now would be to wrap each portion in an IF()
function testing that the output for that VLOOKUP()
is nothing ("") and if so, returning nothing (""), but if not so, returning the lookup result plus the concatenated "comma-space" (and in the last one's case, just the lookup result).
So, like so:
=IF(VLOOKUP(A1, A3:K20, 2, 0) = "", "", VLOOKUP(A1, A3:K20, 2, 0)&",") & IF(VLOOKUP(A1, A3:K20, 3, 0) = "", "", VLOOKUP(A1, A3:K20, 3, 0)&",") & VLOOKUP(A1, A3:K20, 4, 0)