Results 1 to 4 of 4

Thread: Concatenate multiple values

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try this UDF.

    Code:
    Function KCONCAT(ByRef ConcatRange, Optional ByVal blnUnique As Boolean = False, _
                                    Optional ByVal Delim As String = ",") As String
    
        ' Function by Krishnakumar @ ExcelFox.com
        
        ' ConcatRange   : Could be either a Range or array
        ' Delim         : By default the delimiter is ","
        ' blnUnique     : If it's TRUE, return only unique values
        ' Limitation    : Works only single row/column or single dimension array
        
        Dim UpperDimension As Long, i As Long, x
        
        If TypeOf ConcatRange Is Range Then
            
            If (ConcatRange.Rows.Count > 1) * (ConcatRange.Columns.Count = 1) Then
                KCONCAT = Join$(Application.Transpose(ConcatRange.Value), Delim)
            ElseIf (ConcatRange.Rows.Count = 1) * (ConcatRange.Columns.Count > 1) Then
                KCONCAT = Join$(Application.Transpose(Application.Transpose(ConcatRange.Value)), Delim)
            ElseIf (ConcatRange.Rows.Count > 1) * (ConcatRange.Columns.Count > 1) Then
                KCONCAT = CVErr(xlErrNA)
            End If
        
        ElseIf IsArray(ConcatRange) Then
            
            On Error Resume Next
            UpperDimension = UBound(ConcatRange, 2)
            On Error GoTo 0
            
            If UpperDimension = 0 Then
                KCONCAT = Join$(Application.Transpose(Application.Transpose(ConcatRange)), Delim)
            Else
                KCONCAT = Join$(Application.Transpose(ConcatRange), Delim)
            End If
            
            KCONCAT = Replace(Replace(KCONCAT, Delim & "False", ""), "False" & Delim, "")
        
        End If
        If blnUnique Then
            With CreateObject("scripting.dictionary")
                .comparemode = 1
                x = Split(KCONCAT, Delim)
                For i = 0 To UBound(x)
                    .Item(x(i)) = Empty
                Next
                If .Count Then KCONCAT = Join$(.keys, Delim)
            End With
        End If
        
    End Function
    and try

    in E2 and copied down,

    =KCONCAT(IF($B$2:$B$11=B2,$A$2:$A$11),,", ")

    It's an array formula. Conformed with CTRL + SHIFT + ENTER


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-07-2023 at 01:10 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 7
    Last Post: 05-15-2013, 02:56 PM
  2. Loop to two columns and Concatenate values
    By ivandgreat in forum Excel Help
    Replies: 15
    Last Post: 04-14-2013, 08:20 PM
  3. Function to Concatenate Values
    By Admin in forum Download Center
    Replies: 1
    Last Post: 12-13-2012, 11:38 AM
  4. Concatenate Multiple Lookup Values in Single Cell
    By Admin in forum Download Center
    Replies: 4
    Last Post: 04-06-2012, 09:07 PM
  5. Pass Values Between Multiple Userforms
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 07-24-2011, 03:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •