+ Reply to Thread
Results 1 to 3 of 3

combine records in multiple rows of sheet 1 to sheet 2 based on unique number in column

Hybrid View

  1. #1
    Registered User
    Join Date
    01-01-2013
    Location
    ksa
    MS-Off Ver
    Excel 2003
    Posts
    1

    combine records in multiple rows of sheet 1 to sheet 2 based on unique number in column

    kindly provide excel file

    BEFORE
    HH Acct
    1 1234
    1 2345
    1 3456
    1 4567
    2 9876
    2 8765
    3 1113
    4 5556
    4 4447
    4 3335

    AFTER
    HH Acct1 Acct2 Acct3 Acct4 Acct5 Acct6 Acct7
    1 1234 2345 3456 4567
    2 9876 8765 8765
    3 1113
    4 5556 4447 3335

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: combine records in multiple rows of sheet 1 to sheet 2 based on unique number in colum

    See the attached file, after running macro consolidate.

    Sub Consolidate()
    'JBeaucaire  (9/18/2009)
    'Columnar data is Sorted/Matched by column A values, merge all other cells into row format
    Dim LastRow As Long, NextCol As Long
    Dim LastCol As Long, Rw As Long, Cnt As Long
    Dim delRNG As Range
    Application.ScreenUpdating = False
    
    'Sort data
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        Range("A1").CurrentRegion.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes
        
    'Seed the delete range
        Set delRNG = Range("A" & LastRow + 10)
        
    'Group matching names
        For Rw = LastRow To 2 Step -1
            If Cells(Rw, "A").Value = Cells(Rw - 1, "A").Value Then
                Range(Cells(Rw, "B"), Cells(Rw, Columns.Count).End(xlToLeft)).Copy _
                    Cells(Rw - 1, Columns.Count).End(xlToLeft).Offset(0, 1)
                Set delRNG = Union(delRNG, Range("A" & Rw))
            End If
        Next Rw
    
    'Delete unneeded rows all at once
        delRNG.EntireRow.Delete (xlShiftUp)
        Set delRNG = Nothing
    
    'Add titles
        NextCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1
        LastCol = Cells(1, 1).CurrentRegion.Columns.Count
        Range("B1", Cells(1, NextCol - 1)).Copy Range(Cells(1, NextCol), Cells(1, LastCol))
    
    Cells.Columns.AutoFit
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: combine records in multiple rows of sheet 1 to sheet 2 based on unique number in colum

    Oeldere,

    This macro looks great. I am actually trying to do the exact opposite (taking a multi-column view and creating a separate row for each combination) I'm having trouble switching your code for this purpose.

    Would you be able to show me how to reverse this macro?

    Thanks

+ 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