Working from the inside out, the formula first joins the values the 5 cells to the left using the concatenation operator (&) and a single space between each value:
B5&" "&C5&" "&D5&" "&E5&" "&F5
This part of the formula is annoyingly manual. To speed things up, copy &" "& to the clipboard before you start. Then follow this pattern:
[click] [paste] [click] [paste] [click] [paste]
until you get to the last cell reference. It actually goes pretty fast.
The result of this concatenation (before TRIM and SUBSTITUTE run) is a string like this:
"figs apples "
Next, the TRIM function is used to "normalize" all spacing. TRIM automatically strips space at the start and end of a given string, and leaves just one space between all words inside the string. This takes care of extra spaces causes by empty cells.
Finally, the SUBSTITUTE function is used to replace each space (" ") with a comma and space (", "), returning text like this:
Joining cells with other delimiters
To join cells with another delimiter (separator), just adapt the "new_text" argument inside SUBSTITUTE. For example, to join cells with a forward slash, use:
=SUBSTITUTE(TRIM(B7&" "&C7&" "&D7&" "&E7&" "&F7)," ","/")
The output will look like this:
The TEXTJOIN function is a new function available in Excel 365 and Excel 2019. TEXTJOIN allows you to concatenate a range of cells with a delimiter, and will can also be set to ignore empty cells. To use TEXTJOIN with the example above, the formula is: