TextJoin UDF For Excel 2013

前端 未结 4 2108
夕颜
夕颜 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:31

    You may try something like this...

    Function TEXTJOIN(delimiter As String, lookup_id As Range, arr_rng As Range, Optional ignore_empty As Boolean = True) As String
    Dim x, dict
    Dim i As Long
    x = arr_rng.Value
    Set dict = CreateObject("Scripting.Dictionary")
    For i = 1 To UBound(x, 1)
        If x(i, 1) = lookup_id Then
            If Not dict.exists(x(i, 1)) Then
                dict.Item(x(i, 1)) = x(i, 2)
            Else
                dict.Item(x(i, 1)) = dict.Item(x(i, 1)) & IIf(x(i, 2) = "", IIf(ignore_empty, "", delimiter), delimiter & x(i, 2))
            End If
        End If
    Next i
    If dict.Count > 0 Then
        TEXTJOIN = dict.Item(IIf(IsNumeric(lookup_id), lookup_id + 0, lookup_id))
    Else
        TEXTJOIN = ""
    End If
    End Function
    

    Then considering your data is in range A2:B7, try this like below...

    In C2

    =TEXTJOIN(",",A2,$A$2:$B$7)
    

提交回复
热议问题