Summary

To join multiple cell values with a comma, you can use the TEXTJOIN function. In the example shown, the formula in H5, copied down, is:

=TEXTJOIN(", ",TRUE,B5:F5)

TEXTJOIN joins the values in B5:F5 with a comma and a space between each one, and skips empty cells. TEXTJOIN is available in Excel 2019+ and Excel 365. In Excel 2016 and older, you can use a formula based on the SUBSTITUTE and TRIM functions:

=SUBSTITUTE(TRIM(B5&" "&C5&" "&D5&" "&E5&" "&F5)," ",", ")

See below for details and one limitation of this formula.

Generic formula

=TEXTJOIN(", ",TRUE,range)

Explanation

In this example, the goal is to join the values in columns B through F into one cell, with a comma and a space between each value. Some cells are empty, and an empty cell should not add an extra comma.

The TEXTJOIN function

The core of this formula is the TEXTJOIN function, which is designed to join values with a delimiter. TEXTJOIN takes three arguments: the delimiter, ignore_empty, and the values to join, which can be a range:

=TEXTJOIN(", ",TRUE,B5:F5)

The delimiter is a comma followed by a space (", "). Ignore_empty is TRUE, so TEXTJOIN skips the empty cells in the range. In row 5, only B5 and D5 hold values, and the result is "figs, apples". With FALSE, TEXTJOIN would keep the empty cells and add a delimiter for each one: "figs, , apples, , ". The concatenation operator (&) has the same problem: =B5&", "&C5&", "&D5&", "&E5&", "&F5 adds a comma for every cell, empty or not.

To join cells with another delimiter, change the first argument. For example, to join cells with a forward slash:

=TEXTJOIN("/",TRUE,B8:F8) // returns "dates/star fruit/pears/pears/limes"

To put each value on its own line, use CHAR(10) as the delimiter, as explained in Add a line break with a formula.

Join a column into one cell

TEXTJOIN works the same way with a column of values. In the worksheet below, the goal is to join the names in column B into one cell. The formula in D5 is:

=TEXTJOIN(", ",TRUE,B5:B12)

Join a column of cells with commas

TEXTJOIN joins the names from top to bottom and skips the empty cell in B8. A range with more than one row and column also works: TEXTJOIN reads it row by row. To join only the values that meet a condition, like the names in one group, see Look up and return to single cell. For more examples, including unique values in one cell, see the TEXTJOIN function page.

SUBSTITUTE and TRIM (Excel 2016 and older)

Before TEXTJOIN arrived in Excel, joining cells with a comma required a workaround based on SUBSTITUTE and TRIM. In the worksheet below, the formula in H5, copied down, is:

=SUBSTITUTE(TRIM(B5&" "&C5&" "&D5&" "&E5&" "&F5)," ",", ")

Join cells with comma using SUBSTITUTE and TRIM

Working from the inside out, the formula first joins the values in the 5 cells 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 caused by empty cells.

"figs apples"

Finally, the SUBSTITUTE function is used to replace each space (" ") with a comma and space (", "), returning text like this:

"figs, apples"

To join cells with another delimiter, adapt the new_text argument inside SUBSTITUTE. For example, to join cells with a forward slash, use " ","/" at the end of the formula.

The limitation: SUBSTITUTE replaces every space, including spaces inside a value. In row 8, "star fruit" becomes "star, fruit". If your values can contain spaces, test each cell with IF instead, add the delimiter in front of each value, and remove the first delimiter with MID:

=MID(IF(B5<>"",", "&B5,"")&IF(C5<>"",", "&C5,"")&IF(D5<>"",", "&D5,"")&IF(E5<>"",", "&E5,"")&IF(F5<>"",", "&F5,""),3,1000)

MID starts at character 3 to skip the first comma and space. This formula works in any version of Excel and leaves "star fruit" intact.

Video: How to concatenate with line breaks (3 min, free). It's one of 117 lessons in our Core Formula course.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.