Results 1 to 5 of 5

Thread: Multiple Lookup And Return All Values Concatenated With Delimiter

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13

    Multiple Lookup And Return All Values Concatenated With Delimiter

    Hi,

    I need to compare tow columns and get the matched result in single cell.

    Attached sample data for your reference.

    Thanks,
    Prabhu
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Use this

    Code:
    Sub SMC()
    
        Dim rngSource As Range
        Dim var As Variant, varOut As Variant, varOutCombin As Variant
        Dim lngRow As Long, lngCol As Long
        Dim objDic As Object
        Set objDic = CreateObject("Scripting.Dictionary")
        Set rngSource = Range("A2:B14")
        var = rngSource.Value2
        For lngRow = LBound(var) + 1 To UBound(var)
            For lngCol = LBound(var, 2) To UBound(var, 2)
                If IsEmpty(var(lngRow, lngCol)) Then
                    var(lngRow, lngCol) = var(lngRow - 1, lngCol)
                Else
                    If lngCol = LBound(var, 2) Then
                        objDic.Item(var(lngRow, lngCol)) = 0
                    End If
                End If
            Next lngCol
        Next lngRow
        varOut = objDic.Keys
        ReDim varOutCombin(1 To objDic.Count)
        For lngRow = LBound(var) + 1 To UBound(var)
            For lngCol = LBound(varOut) To UBound(varOut)
                If var(lngRow, 1) = varOut(lngCol) Then
                    If IsEmpty(varOutCombin(lngCol + 1)) Then
                        varOutCombin(lngCol + 1) = var(lngRow, 2)
                    Else
                        varOutCombin(lngCol + 1) = varOutCombin(lngCol + 1) & "," & var(lngRow, 2)
                    End If
                End If
            Next lngCol
        Next lngRow
        rngSource.Offset(1).ClearContents
        rngSource(2, 1).Resize(5).Value = Application.Transpose(varOut)
        rngSource(2, 2).Resize(5).Value = Application.Transpose(varOutCombin)
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    Hi,

    I am not sure a formula can do your work, so i have created a macro to do it.
    Attached Files Attached Files

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    .. with one loop..

    Code:
    Sub kTest()
        
        Dim k, i As Long, sKey  As String, sItems As String, d As Object
        
        k = Range("a2").CurrentRegion.Resize(, 2).Value2
        
        Set d = CreateObject("scripting.dictionary")
            d.comparemode = 1
        
        For i = 2 To UBound(k, 1)
            If LenB(k(i, 1)) Then sKey = k(i, 1)
            If LenB(sKey) Then
                sItems = d.Item(sKey)
                If LenB(sItems) Then
                    d.Item(sKey) = sItems & "," & k(i, 2)
                Else
                    d.Item(sKey) = k(i, 2)
                End If
            End If
        Next
        
        With Range("d10")
            .Resize(d.Count) = Application.Transpose(d.keys)
            .Offset(, 1).Resize(d.Count) = Application.Transpose(d.items)
        End With
        
    End Sub
    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)

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Thank you all!

Similar Threads

  1. Vlookup to Return Multiple Values
    By Admin in forum Download Center
    Replies: 9
    Last Post: 02-17-2017, 07:03 PM
  2. Replies: 3
    Last Post: 07-29-2013, 09:15 AM
  3. Replies: 14
    Last Post: 06-27-2013, 10:57 AM
  4. Multiple Value Return Using Lookup
    By excel_1317 in forum Excel Help
    Replies: 1
    Last Post: 06-25-2013, 01:06 PM
  5. Replies: 4
    Last Post: 04-24-2013, 10:04 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
  •