Macro to concatenate data based on adjacent matching cells

I had the first part of this macro built last year but need to add another criteria to it. We were just matching on company name last time.
(see: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28437869.html)

I have very basic customer list and need to consolidate the student name cell IF the company name, address, and refresher date cells are the same.

How it looks now (there are columns up to P with data):
How it currently is
How it needs to be (matched on company, address, AND refresher date):
How it needs to be
THANK YOU!
DaniellefischerAsked:
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.

aikimarkCommented:
please post a workbook with sample data

aikimark -- zone advisor
0
Saurabh Singh TeotiaCommented:
Enclosed is the workbook and code for your reference which will do what you are looking for..

Sub comparedata()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

    Dim i As Long
    i = 2

    Do Until i > Cells(Cells.Rows.Count, "A").End(xlUp).Row

        If Trim(UCase(Cells(i, "a").Value)) = Trim(UCase(Cells(i + 1, "a").Value)) And Trim(UCase(Cells(i, "b").Value)) = Trim(UCase(Cells(i + 1, "b").Value)) And Trim(UCase(Cells(i, "d").Value)) = Trim(UCase(Cells(i + 1, "d").Value)) And Trim(UCase(Cells(i, "e").Value)) = Trim(UCase(Cells(i + 1, "e").Value)) And Trim(UCase(Cells(i, "j").Value)) = Trim(UCase(Cells(i + 1, "j").Value)) Then

            Cells(i, "g").Value = Cells(i, "g").Value & ", " & Cells(i + 1, "g").Value
            Rows(i + 1).Delete
        Else
            i = i + 1
        End If


    Loop
Cells.EntireRow.AutoFit

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

Open in new window


Before shows the data in your format and after is once the macro is run...

Saurabh...
Test.xlsm
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
Rgonzo1971Commented:
Hi,

pls try

Sub Consolidate_Data()
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Set Rng = Selection
    Do Until ActiveCell.Value = ""

    If strCompMatch = Join(Application.Index(ActiveCell.Resize(1, 6).Value, 1, 0), "|") & "|" & Range("J" & ActiveCell.Row).Value Then
            strStudents = strStudents & ", " & ActiveCell.Offset(0, 6).Value
            ActiveCell.EntireRow.Delete
        Else
            If strStudents <> "" Then 'after first iteration
                ActiveCell.Offset(-1, 6).Value = strStudents
           End If
            strStudents = ActiveCell.Offset(0, 6).Value
            strCompMatch = Join(Application.Index(ActiveCell.Resize(1, 6).Value, 1, 0), "|") & "|" & Range("J" & ActiveCell.Row).Value
            ActiveCell.Offset(1, 0).Select
        End If
    Loop
    ActiveCell.Offset(-1, 6).Value = strStudents
End Sub

Open in new window

Regards
0
aikimarkCommented:
Here's another approach.  Like the others, already posted, it assumes that the data is sorted in A:G,J order.
Option Explicit

Sub Q_28655961()
    Dim dicKeys As Object
    Dim rng As Range
    Dim strKey As String
    Dim vItem As Variant
    
    Set dicKeys = CreateObject("scripting.dictionary")
    
    Application.ScreenUpdating = False
    
    ActiveSheet.Columns(7).Insert
    ActiveSheet.Columns(7).Value = ActiveSheet.Columns(11).Value
    
    For Each rng In ActiveSheet.Range(ActiveSheet.Range("a1"), ActiveSheet.Range("a1").End(xlDown))
        strKey = Join(Application.WorksheetFunction.Index(ActiveSheet.Range("A" & rng.Row & ":G" & rng.Row).Value, 1, 0), vbTab)
        If dicKeys.exists(strKey) Then
            dicKeys(strKey) = dicKeys(strKey) + 1
        Else
            dicKeys(strKey) = 1
        End If
    Next
    
    For Each rng In ActiveSheet.Range(ActiveSheet.Range("a1"), ActiveSheet.Range("a1").End(xlDown))
        strKey = Join(Application.WorksheetFunction.Index(ActiveSheet.Range("A" & rng.Row & ":G" & rng.Row).Value, 1, 0), vbTab)
        If dicKeys(strKey) <> 1 Then
            rng.Cells(1, 8).Value = Join(Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(ActiveSheet.Range("H" & rng.Row & ":H" & rng.Row + dicKeys(strKey) - 1).Value, 0, 1)), ", ")
            ActiveSheet.Range(rng.Offset(1).EntireRow, rng.Offset(dicKeys(strKey) - 1).EntireRow).Delete
        End If
    Next
    ActiveSheet.Columns(7).Delete
    Application.ScreenUpdating = True
    Set dicKeys = Nothing
End Sub

Open in new window

0
DaniellefischerAuthor Commented:
Thank you all for your solutions! They all worked perfectly for the data. You have just saved me endless hours of editing.
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.