Results 1 to 3 of 3

Macro that merges duplicate rows based on unique values - Need to edit current code

Threaded View

  1. #1
    Registered User
    Join Date
    05-30-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    3

    Macro that merges duplicate rows based on unique values - Need to edit current code

    Hiya,

    I was able to locate a macro that does exactly what I need; however, I need to make a slight change to the but I have limited vba knowledge and am hoping someone can help me.

    I have a spreadsheet that lists employees and their certifications. If an employee has multiple, then they will show up on as many rows as they have certifications.

    The macro I have merges them into one row with a line break, but only the first column's unique value has been merged while the other columns containing their own unique values are duplicated when I want them to show up only once. Example: Jane Doe shows up 2 times on the report. Her name should only show up once on the row, not 2 times with a line break.

    Here is the code. I have also attached an example of what I need. Because the attachment is a simpler version of the actual report, is it possible to specify which rows have the unique values and which ones don't? Any help is appreciated.

    Sub Test()
        Dim a, i As Long, w(), c As Long, z
        With Range("a1")
            a = .CurrentRegion
            With CreateObject("scripting.dictionary")
                .comparemode = vbTextCompare
                For i = 2 To UBound(a, 1)
                    If Not IsEmpty(a(i, 1)) Then
                        If Not .exists(a(i, 1)) Then
                            ReDim w(1 To UBound(a, 2))
                            For c = 1 To UBound(a, 2): w(c) = a(i, c): Next
                                .Add a(i, 1), w
                            Else
                                w = .Item(a(i, 1)): w(1) = a(i, 1)
                                For c = 2 To UBound(a, 2)
                                    w(c) = .Item(a(i, 1))(c) & Chr(10) & a(i, c)
                                Next
                                .Item(a(i, 1)) = w
                            End If
                        End If
                    Next
                    z = .items
                End With
                .CurrentRegion.Offset(1).ClearContents
                For i = 0 To UBound(z)
                    .Offset(i + 1).Resize(, UBound(z(i))).Value = z(i)
                Next
            End With
        End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find count of Unique or Duplicate Values based on Concatenated values in 2 columns
    By bdicarlo1 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-03-2014, 12:42 AM
  2. [SOLVED] Macro to merge duplicate rows unique values - current macro not working
    By aimeecrystalaid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2013, 03:42 PM
  3. How to merge duplicate rows with some unique data with VBA code
    By katkur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2013, 11:17 AM
  4. Merge Duplicate Rows unique values into single rows for an infinite amount of columns/rows
    By aimeecrystalaid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2013, 08:43 PM
  5. [SOLVED] Edit Recorded Macro to filter column with about 200k rows based on a list of values.
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-19-2012, 03:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1