Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate a range of cells with a comma

I'd like to combine a range of cells of data so that it comes out with just one text string and a comma + space between each one. I have been successful in using concatenate:

=ArrayFormula(concatenate(C3:F&", ")) 

but there are extra commas that don't need to be there in between some data and a lot of extra commas at the end.

Example Sheets.

like image 923
Niels van der Tak Avatar asked Dec 13 '16 16:12

Niels van der Tak


People also ask

How do you CONCATENATE a range of cells in Excel?

CONCATENATE Excel Range (Without any Separator)Select the entire formula and press F9 (this converts the formula into values). Remove the curly brackets from both ends. Add =CONCATENATE( to the beginning of the text and end it with a round bracket). Press Enter.

How do you combine names in Excel with commas?

You need to type =CONCATENATE first and then populate the other fields in the formula. Pay attention to the placement of the commas and parentheses. In your formula, you will replace A2 and B2 with the cells that contain the data that you want to combine.


1 Answers

A easy way (if you don't have that many columns) would be to use a literal array and filter out the empty cells with query. Something like this

=join(", ", query({C3:C; D3:D; E3:E; F3:F}, "where Col1 <>''")) 

Also see cell A1 in the spreadsheet you shared.

UPDATED: An alternative (and shorter) way would be to use textjoin()

=textjoin(", ", 1, C2:F) 
like image 121
JPV Avatar answered Sep 25 '22 13:09

JPV