+ Reply to Thread
Results 1 to 6 of 6

Consolidating similar rows with unique columns

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Consolidating similar rows with unique columns

    Here's a couple of codes for you.
    The first will work OK on a Mac but does require the data to be presorted as you posted. That's easily done if needed.
    The second in really only for your interest since it uses the scripting dictionary which in general doesn't work on a Mac. But this code doesn't need pre-sorted data.
    Both were tested on the data you posted in Sheets"Raw Data"), with consolidation on the (initially assumed empty) Sheets("sheet3") and Sheets("sheet4") respectively.
    Note also that the results may look different because the original formats haven't been transferred, and neither have the column headers. Both easily done if needed.
    Sub for_mac() 'works on mac with sorted data as posted. can include a pre-sort if needed
    Const c& = 25
    Dim r, a, x(), u(), i, j, s, k
    Sheets("Raw Data").Activate
    r = Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
    a = Cells(1).Resize(r, c)
    ReDim x(1 To r, 1 To c), u(r)
    
    For i = 2 To r
       u(i) = Join(Array(a(i, 2), a(i, 3), a(i, 4), a(i, 5), _
            a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10), a(i, 11)), Chr(30))
    Next i
    k = 1: s = 2
    For j = 2 To 25: x(k, j) = a(s, j): Next j
    For i = 3 To r
        If u(i) <> u(s) Then
            s = i: k = k + 1
            For j = 2 To 25: x(k, j) = a(s, j): Next j
        Else
            For j = 12 To 25: x(k, j) = x(k, j) & a(i, j): Next j
        End If
    Next i
    Sheets("Sheet3").Range("A2").Resize(k, c) = x
    
    End Sub
    and
    Sub Uses_Scripdict() 'won't usually work on Mac
    Const c& = 25
    Dim d As Object, r, a, x(), u, i, j
    Sheets("Raw Data").Activate
    
    Set d = CreateObject("scripting.dictionary")
    r = Cells.Find("*", , , , xlByRows, xlPrevious).Row
    a = Cells(1).Resize(r, c)
    ReDim x(1 To r, 1 To c)
    
    For i = 2 To r
        u = Join(Array(a(i, 2), a(i, 3), a(i, 4), a(i, 5), _
            a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10), a(i, 11)), Chr(30))
        If Not d.exists(u) Then
            d(u) = d.Count + 1
            For j = 2 To 11: x(d(u), j) = a(i, j): Next j
        End If
        For j = 12 To c: x(d(u), j) = x(d(u), j) & a(i, j): Next j
    Next i
    Sheets("Sheet4").Range("A2").Resize(d.Count, c) = x
    
    End Sub
    Last edited by kalak; 11-21-2014 at 10:34 PM.

  2. #2
    Registered User
    Join Date
    02-15-2013
    Location
    Gambier, OH
    MS-Off Ver
    Excel 2011 for Mac Version 14.4.3
    Posts
    10

    Re: Consolidating similar rows with unique columns

    That worked out perfectly, kalak. Thank you! I actually only tried the first formula and it did what I needed. The other sorting macro that stanleydgromjr helped me with a few years ago is still very useful, so I just run that first.

    Again, thank you for your help!

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Consolidating similar rows with unique columns

    Thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. 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
  2. Replies: 4
    Last Post: 01-16-2013, 10:06 PM
  3. Help merging similar rows into columns
    By MR UZZI in forum Excel General
    Replies: 4
    Last Post: 11-26-2012, 12:16 AM
  4. Adding similar rows for different columns
    By riznarf in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 08-31-2011, 09:37 AM
  5. consolidating multiple rows of similar data
    By opticsnake in forum Excel General
    Replies: 2
    Last Post: 10-16-2009, 03:23 PM

Tags for this Thread

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