EXCEL - Merge duplicate and append unique Cells

I have a listing of thousands of lines that are duplicate base off some unique primary cells.  There are some other cells that are unique.  I would like to append/combine these cells.  Is this possible?

I am attaching an example with the raw data and final output.  Not sure if Excel can do this or some VBA script can?

Example
holemaniaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

holemaniaAuthor Commented:
The primary key/column would be A and B in this case.  A and B will be the same, but column C and D changes.  I want to remove duplicate and then just append column C and D with a comma separating them.
0
krishnakrkcCommented:
Option Explicit

Sub kTest()
    
    Dim dic As Object, i As Long, s As String
    Dim k, kk(), n As Long, c As Long
    
    Const SheetName As String = "Sheet2"      '<<<<<< adjust the sheet name
    
    Set dic = CreateObject("scripting.dictionary")
        dic.comparemode = 1
    
    With ThisWorkbook.Worksheets(SheetName)
        k = .Range("a1").CurrentRegion.Value2
        ReDim kk(1 To UBound(k, 1), 1 To UBound(k, 2))
        For i = 2 To UBound(k, 1)
            s = vbNullString
            s = k(i, 1) & "|" & k(i, 2) 'col a & b
            If Len(s) Then
                If Not dic.exists(s) Then
                    n = n + 1
                    For c = 1 To UBound(k, 2)
                        kk(n, c) = k(i, c)
                    Next
                    dic.Item(s) = n
                Else
                    c = dic.Item(s)
                    kk(c, 3) = kk(c, 3) & ", " & k(i, 3) 'update col c
                    kk(c, 4) = kk(c, 4) & ", " & k(i, 4) 'update col d
                End If
            End If
        Next
        If n Then
            .Range("a1").CurrentRegion.Offset(1).ClearContents
            .Range("a2").Resize(n, UBound(kk, 2)).Value = kk
        End If
    End With
    
End Sub

Open in new window


Kris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
holemaniaAuthor Commented:
Awesome.  Works perfectly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.