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
You can create your own function to do this in VBA. This should do it:
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: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
=MyConcat(A2)
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&" "))