+ Reply to Thread
Results 1 to 4 of 4

Merging rows with some duplicate and some unique data - into one row

Hybrid View

  1. #1
    Registered User
    Join Date
    01-15-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2003
    Posts
    2

    Merging rows with some duplicate and some unique data - into one row

    Exporting data from a school database will produce student records on multiple lines, depending on how may parents/guardians a student has in the system. If a student has just one parent, only one row is created. If a student has two (or more) other parents, an additional row is created for each. All of the Student’s information on each row will be identical, but the fields for a parent will be different.

    I want to merge rows with multiple parents and have all columns for each parent part of the same row (See attachment).

    At most there could be 4 unique parent/guardians for each student.
    Attached Files Attached Files
    Last edited by kennedy40; 01-18-2012 at 03:29 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Merging rows with some duplicate and some unique data - into one row

    Hi kennedy40
    Welcome to excel forum

    Why not just use the advance filter unique values?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Merging rows with some duplicate and some unique data - into one row

    Hi kennedy40
    This code is in the attached. See if it does as you require.
    Option Explicit
    Sub combine_guardians()
        Dim LR As Long
        Dim header1 As Variant
        Dim header2 As Variant
        Dim header3 As Variant
        Dim header4 As Variant
        Dim rng As Range
        Dim i As Long
        Dim r As Long
    
        header1 = Array("relation.1", "First Name.1", "Last Name.1", "E-mail Address.1", "Home Phone.1", "Cellular Phone.1")
        header2 = Array("relation.2", "First Name.2", "Last Name.2", "E-mail Address.2", "Home Phone.2", "Cellular Phone.2")
        header3 = Array("relation.3", "First Name.3", "Last Name.3", "E-mail Address.3", "Home Phone.3", "Cellular Phone.3")
        header4 = Array("relation.4", "First Name.4", "Last Name.4", "E-mail Address.4", "Home Phone.4", "Cellular Phone.4")
        Range("I1").Resize(1, 6).Value = header1
        Range("O1").Resize(1, 6).Value = header2
        Range("U1").Resize(1, 6).Value = header3
        Range("AA1").Resize(1, 6).Value = header4
    
        Application.ScreenUpdating = False
        LR = Range("A" & Rows.Count).End(xlUp).Row
        Set rng = Range("A2:A" & LR)
        With rng
            r = 6
            For i = LR To 1 Step -1
                If rng(i).Value = rng(i).Offset(-1, 0).Value Then
                    rng(i).Offset(0, 8).Resize(1, r).Copy
                    rng(i).Offset(-1, 14).Resize(1, r).PasteSpecial
                    rng(i).EntireRow.Delete
                    r = r + 6
                Else
                    r = 6
                End If
            Next i
        End With
        Cells.Columns.AutoFit
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    01-15-2012
    Location
    Oregon
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Merging rows with some duplicate and some unique data - into one row

    John,
    This solved my problem completely. Thank you! This will be an immense time saver.

    David

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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