TextJoin UDF For Excel 2013

前端 未结 4 2104
夕颜
夕颜 2020-12-18 13:17

I am trying to utilize a UDF version of TextJoin since I am using Excel 2013 - but this function is not properly returning the accurate data.

My data-set in Excel lo

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 13:32

    If your data is in columns A and B, this code should work.

    Sub TEXTJOIN()
    Dim i As Long, str As String, k As Long
    Columns("A:B").Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes
    str = Cells(2, 2)
    k = 2
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, 1) = Cells(i + 1, 1) Then
            str = str & "," & Cells(i + 1, 2)
        Else
            Cells(k, 4) = Cells(i, 1)
            Cells(k, 5) = str
            k = k + 1
            str = Cells(i + 1, 2)
        End If
    Next i
    End Sub
    

    I leave the part to you to convert this to an UDF.

提交回复
热议问题