Search code examples
excelexcel-formulastring-concatenationtextjoin

Pick values from multiple cells and paste output in one cell


I have a dataset which looks like:

A   0.998315185
B   0.232720507
C   0.010558964
D   0.004246209
E   0.002552556

I want to paste below output in one cell as:

0.998315185A+0.232720507B+0.010558964C+0.004246209D+0.002552556E

So that I can copy this and use it elsewhere.


Solution

  • You may try this User Defined Function. Use this function in a cell on the sheet like this...

    =CombineData(A1:B5)
    

    User Defined Function:

    Function CombineData(ByVal Rng As Range) As String
    Dim i As Long, j As Long
    Dim str As String
    Dim cell As Range
    For i = 1 To Rng.Rows.Count
        For j = Rng.Columns.Count To 1 Step -1
            If str = "" Then
                str = Rng.Cells(i, j)
            Else
                str = str & Rng.Cells(i, j)
            End If
        Next j
        str = str & "+"
    Next i
    CombineData = str
    End Function