Combining data in columns

Jezza25

New Member
Joined
Jan 29, 2011
Messages
16
Hi,

Need to combine data from multiple columns together witha comma between each column. The formula I have is

=AB4&", "&AC4&", "&AD4&", "&AE4

The creates a result for the first line of Apple, Pear, Grape, Banana

however not all columns have all 4 columns populated, the data does move left to right but if only the first 2 columns are populated I get Apple, Pear,,,

I am seeking a formula so that after the last name I have something in it does not continue adding commas

ta

Jezza
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Is there always guaranteed to be at least one entry, and will it always appear in column AB?

If column AB will always have an entry, this should do what you want:
Code:
=AB4 & IF(AC4<>"",", " & AC4,"")  & IF(AD4<>"",", " & AD4,"") & IF(AE4<>"",", " & AE4,"")
 
Last edited:
Upvote 0
if you don't have 2016.....

=SUBSTITUTE(TRIM(AB4&" "&AC4&" "&AD4&" "&AE4)," ",", ")

if you do....

=TEXTJOIN(", ",1,AB4:AE4)
 
Upvote 0
if you don't have 2016.....

=SUBSTITUTE(TRIM(AB4&" "&AC4&" "&AD4&" "&AE4)," ",", ")
What if a cell contains more than one word (for example "Gala Apple")?



Is there always guaranteed to be at least one entry, and will it always appear in column AB?

If column AB will always have an entry, this should do what you want:
Code:
=AB4 & IF(AC4<>"",", " & AC4,"")  & IF(AD4<>"",", " & AD4,"") & IF(AE4<>"",", " & AE4,"")
And if not...

=MID(IF(AB4<>"",", "&AB4,"")&IF(AC4<>"",", "&AC4,"")&IF(AD4<>"",", "&AD4,"")&IF(AE4<>"",", "&AE4,""),2,999)
 
Upvote 0
If you would like a Vba solution try this script

Your Quote:
"Need to combine data from multiple columns together witha comma between each column"
You did not say how many columns
With this script
It combines all the data in four columns into column "A" with a comma between each value
It continues to do this till it reaches the last filled cell in column "A"
You can change the number of columns by changing the value in the script marked in red
This script could be modified to accomplish this by combining all columns in one row depending on number of columns filled in that row. If you wanted that feature let me know.

Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim b As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
    
        For b = 2 To[COLOR="#FF0000"] 4[/COLOR]
            If Cells(i, b).Value <> "" Then
            Cells(i, 1).Value = Cells(i, 1) & "," & Cells(i, b).Value
            End If
        Next
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
[COLOR=#333333]=MID(IF(AB4<>"",", "&AB4,"")&IF(AC4<>"",", "&AC4,"")&IF(AD4<>"",", "&AD4,"")&IF(AE4<>"",", "&AE4,""),2,999)[/COLOR]
You know, I tried the other way, trying to figure out how to drop the two right-most values first, but that doesn't work so well when you don't know the length.
I cannot believe I didn't think to go the other way, and just drop the first few characters...
 
Upvote 0

Forum statistics

Threads
1,223,417
Messages
6,171,996
Members
452,438
Latest member
jimmyleung

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