Joining cell content with comma spacing

Raziel7

New Member
Joined
Apr 12, 2018
Messages
8
Hi Guys,

Really looking forward to your help with this one.

I needs to combine cell data and have a comma spacing between them. however I don't want empty cells to merge.

For example,
1.Apple
2.Tomato
3.Banana
4.Apple
5.Apple
6.
7. Tomato
8.

<tbody>
</tbody>


I need it to read:

Apple,Tomato,Banana,Apple,Apple,Tomato ( notice how the gap was ignore for row 6 and 8.

I know that the concatenate function can help but I have having trouble with the gap.

I am using the following:

=concatenate(A1,",",A2,","A3) and so on. but the blank cell are affecting the end result.

Thanks in advance for your help,

Raziel
 
This will be So much easier if OP (or I) have the TEXTJOIN function.
I don't have the version of Excel with TEXTJOIN either, but depending on the workbook is to be used, having it may not be the answer. If the workbooks is to be used by more than the OP, those individuals would also have to have the version of Excel with TEXTJOIN in it as well or the formulas would fail when they opened the workbook.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I don't have the version of Excel with TEXTJOIN either, but depending on the workbook is to be used, having it may not be the answer. If the workbooks is to be used by more than the OP, those individuals would also have to have the version of Excel with TEXTJOIN in it as well or the formulas would fail when they opened the workbook.

Thanks Rick,

I thinking Concatenate will do the trick, but I need to try to remove the ,,,,,,,,,,, at the end.

I have simply put the function in another cell where I can copy the combined cells and paste on to another program.

regards,

Raziel
 
Upvote 0
My updated formula in Post #10 should do it, try it with your data.
 
Upvote 0
Hi PVR928, Jtakw and Rick Rothstein,

Thank you all very much for your help. I can't thank you enough.

I used the following, and it worked perfectly:

=SUBSTITUTE(TRIM(CONCATENATE(A1," ",A2," ",A3," ",A4," ",A5," ",A6," ",A7," ",A8," ",A9," ",A10," ",A11," ",A12))," ",",")

I am still interested in the VBA option and will give it a go with the UDF suggestion.

you guys are champions and thanks again,

Raziel
 
Upvote 0
Hi PVR928, Jtakw and Rick Rothstein,

Thank you all very much for your help. I can't thank you enough.

I used the following, and it worked perfectly:

=SUBSTITUTE(TRIM(CONCATENATE(A1," ",A2," ",A3," ",A4," ",A5," ",A6," ",A7," ",A8," ",A9," ",A10," ",A11," ",A12))," ",",")

I am still interested in the VBA option and will give it a go with the UDF suggestion.

you guys are champions and thanks again,

Raziel

That's my formula from Post #8 , but as Rick pointed out, if you have 2 or more words in the same cell, it'll fail, my formula in Post #10 should work just as well, but will not fail with more than 1 word in a single cell. If there won't be more than 1 word in a single cell, than the Post #8 formula should work fine.
 
Upvote 0
You're welcome, welcome to the forum.
 
Upvote 0
Hi Raziel7

This is not as dynamic as my first attempt, and it assumes all of the text is contained only in the range A9:A40 on worksheet "LOAD SHEET".

The output is in range C1 of worksheet "LOAD SHEET".

Code:
Option Explicit
Sub ConcatenateStrings()
Dim ws As Worksheet
Dim rRange As Range
Dim rCell As Range
Dim sOutputString As String
Set ws = Sheets("LOAD SHEET")
Set rRange = ws.Range("A9:A40")
For Each rCell In rRange
    
    If rCell.Row = 9 Then
        
        sOutputString = Trim(rCell.Value2)
            
    Else
        
        sOutputString = sOutputString & "," & Trim(rCell.Value2)
            
    End If
        
Next rCell
ws.Range("C1") = sOutputString
End Sub

Cheers

pvr928
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,856
Members
449,411
Latest member
adunn_23

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