Concatenate column dynamic cell contents

TBP

Board Regular
Joined
Jul 30, 2011
Messages
55
Hi,
Is there a formula I can use to concatenate a column with an unknown count of how many rows contain data.
examples

Heading1
bob
jane
rick

= bob jane rick

Heading1
bob

=bob

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
you could set your formula like the below there is no simple way unless you use code to do this

=TRIM(CONCATENATE(A1&" ",A2&" ",A3&" ",A4&" "))
 
Upvote 0
You can create your own function to do this in VBA. This should do it:
Code:
Function MyConcat(StartCell As Range) As String
'   Concatenates all entries in a column starting in starting cell referenced in formula


    Dim myLastCell As Range
    Dim cell As Range
    Dim myString As String
    
'   Find last cell with data in the selected column
    Set myLastCell = Cells(Rows.Count, StartCell.Column).End(xlUp)
    
'   Combine all non-blank entries
    For Each cell In Range(StartCell, myLastCell)
        If cell <> "" Then
            myString = myString & cell & " "
        End If
    Next cell
    
'   Remove last space
    MyConcat = Trim(myString)
    
End Function
So, if you wanted to concatenate all the entries in column A, starting on row 2, you would just then type this formula into your sheet:
=MyConcat(A2)
 
Upvote 0
You can create your own function to do this in VBA. This should do it:
Code:
Function MyConcat(StartCell As Range) As String
'   Concatenates all entries in a column starting in starting cell referenced in formula


    Dim myLastCell As Range
    Dim cell As Range
    Dim myString As String
    
'   Find last cell with data in the selected column
    Set myLastCell = Cells(Rows.Count, StartCell.Column).End(xlUp)
    
'   Combine all non-blank entries
    For Each cell In Range(StartCell, myLastCell)
        If cell <> "" Then
            myString = myString & cell & " "
        End If
    Next cell
    
'   Remove last space
    MyConcat = Trim(myString)
    
End Function
So, if you wanted to concatenate all the entries in column A, starting on row 2, you would just then type this formula into your sheet:
=MyConcat(A2)

that's cool :-)
 
Upvote 0
Joe4 awesome works great!
But can I run it from "PERSONAL.XLSB" when I do I get #NAME? error?
Thanks
 
Upvote 0
you could set your formula like the below there is no simple way unless you use code to do this

=TRIM(CONCATENATE(A1&" ",A2&" ",A3&" ",A4&" "))

bewsh1987 I like the use of TRIM for a code free version.
Thanks
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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