Combine Cell Text

Solved/Closed
ad1959 Posts 10 Registration date Thursday 6 March 2014 Status Member Last seen 18 August 2020 - 10 Feb 2020 à 23:41
 ad1959 - 11 Feb 2020 à 23:25
Hi,
I am after an easy way to combine text in several rows into one cell.
The number of rows that need combining will vary from 2- 10
(Would be easier if the client who supplies the spreadsheet would learn how to use more than 1 line in a cell).

Column A is a date which is merged over several rows
Column B is over several rows and will vary
Column C is the result required.


Any assistance will be appreciated
Related:

2 responses

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
11 Feb 2020 à 12:17
Hi Ad1959,

The easiest way would be to use a vba code:
Sub RunMe()
Dim fRow, lRow As Integer
Dim cValue

lRow = Range("B" & Rows.Count).End(xlUp).Row
fRow = Range("A" & Rows.Count).End(xlUp).Row

Do
    For Each cell In Range(Cells(fRow, "B"), Cells(lRow, "B"))
        cValue = cValue & cell.Value & "-"
    Next cell
    
    cValue = Left(cValue, Len(cValue) - 1)
    Range("C" & fRow).Value = cValue
    
    lRow = fRow - 1
    fRow = Range("A" & fRow).End(xlUp).Row
    
    cValue = vbNullString
Loop Until fRow = 1

End Sub


To implement:
Alt+F11 to open VBA window, go to top menu Insert > Module. Paste code in the big white field. Close window. Back at the Excel screen Alt+F8 to display available codes and double click RunMe.

Save before running the code, so you can reload your file when you don't like the result.

Best regards,
Trowa
Thanks TrowaD,

Works perfectly
Daniel Telele Posts 1227 Registration date Tuesday 7 March 2017 Status Member Last seen 4 November 2021   6,276
11 Feb 2020 à 02:16
Hello,

You can use the Concatenate function in Excel. Use the function below in the destination cell, then add the columns you want to concatenate.


=CONCATENATE(Column1, Column2, etc)


Regards,
Thanks Daniel, But not what I was after another contributor has provided a solution