Formula to Combine Range on row to One Cell Separated by Comma

L

Legacy 436357

Guest
Hello,

Is there a formula to combine cells on the same row (A2:H2) with each value separated by comma and one space ignoring any blank cells?

Thank you
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If you have TextJoin you can use
=TEXTJOIN(", ",TRUE,A2:H2)
 
Upvote 0
If you don't have TEXTJOIN, here's a UDF that I think will do it: ConcatRange(A2:H2,", ")

Code:
Function ConcatRange(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
 If Not (IsEmpty(Cell.Value)) Then
  Result = Result & Cell.Value & Separator
 Else
 End If
Next Cell
ConcatRange = Left(Result, Len(Result) - 2)
 
Last edited:
Upvote 0
ALT+F11 and place the code in a MODULE. If you don't have a module, right click in the VBA editor on ThisWorkbook and insert a module, then paste the code.

Then, from a cell, use it like any other function: =ConcatRange(A2:H2,", ")

Sorry, my last line of the function didn't copy...try this:

Code:
Function ConcatRange(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
 If Not (IsEmpty(Cell.Value)) Then
  Result = Result & Cell.Value & Separator
 Else
 End If
Next Cell
ConcatRange = Left(Result, Len(Result) - 2)
End Function
 
Last edited:
Upvote 0
Thanks I get Expected End Function error
 
Last edited by a moderator:
Upvote 0
I have excel 2010 sorry it isn't available
You are only processing eight cells on the row, so if you wanted to stay with a formula solution then you could use this one...
Code:
[table="width: 500"]
[tr]
	[td]=MID(IF(A2="","",", "&A2)&IF(B2="","",", "&B2)&IF(C2="","",", "&C2)&IF(D2="","",", "&D2)&IF(E2="","",", "&E2)&IF(F2="","",", "&F2)&IF(G2="","",", "&G2)&IF(H2="","",", "&H2),3,999)[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top