+ Reply to Thread
Results 1 to 11 of 11

Combine multiple rows into one row

Hybrid View

  1. #1
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Combine multiple rows into one row

    Hi.. Badly need a help in the excel collation data. I need to combine data from multiple rows into one row in a separate sheet. My worksheet has 92,000 rows and 80 columns in this I have a a column which has a unique id but have a different values in rows and most of them are blank. I have attached the sample spread sheet for reference. Can any provide me the macro Pls.
    Attached Files Attached Files
    Last edited by gan143; 09-09-2012 at 09:15 AM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Combine multiple rows into one row

    Try this

    Sub abc()
     Dim i As Long, ii As Long
    
     Dim a
     a = Range("a2:bc" & Cells(Rows.CountLarge, "a").End(xlUp).Row)
     With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(a, 1)
            For ii = 2 To UBound(a, 2)
                If Not .Exists(a(i, 1)) Then
                    .Item(a(i, 1)) = a(i, 1)
                Else
                    If Not IsEmpty(a(i, ii)) Then
                        .Item(a(i, 1)) = .Item(a(i, 1)) & "," & a(i, ii)
                    End If
                End If
            Next
        Next
        a = .Items
        Worksheets.Add after:=Worksheets(Worksheets.Count)
        For i = LBound(a) To UBound(a)
            s = Split(a(i), ",")
            Cells(i + 1, 1).Resize(, UBound(s) + 1) = s
        Next
            Range("a1").Resize(i, UBound(a)).Borders.LineStyle = xlContinuous
     End With
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Combine multiple rows into one row

    Hi Mike.. It is working fine.. but I have received an error for this line.. Range("a1").Resize(i, UBound(a)).Borders.LineStyle = xlContinuous.. Can you help me understand on this pls.. or I can ignore & starting working the sheet...

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Combine multiple rows into one row

    Try this one, I believe my first code was missing the first column.

    Sub abc()
     Dim i As Long, ii As Long
    
     Dim a
     a = Range("a2:bc" & Cells(Rows.CountLarge, "a").End(xlUp).Row)
     With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(a, 1)
            For ii = 1 To UBound(a, 2)
                If Not .Exists(a(i, 1)) Then
                    .Item(a(i, 1)) = a(i, 1)
                Else
                    If Not IsEmpty(a(i, ii)) And ii > 1 Then
                        .Item(a(i, 1)) = .Item(a(i, 1)) & "," & a(i, ii)
                    End If
                End If
            Next
        Next
        a = .Items
        Worksheets.Add after:=Worksheets(Worksheets.Count)
        For i = LBound(a) To UBound(a)
            s = Split(a(i), ",")
            Cells(i + 1, 1).Resize(, UBound(s) + 1) = s
        Next
            Range("a1").Resize(i, UBound(a) + 1).Borders.LineStyle = xlContinuous
     End With
    End Sub

  5. #5
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Combine multiple rows into one row

    Mike.. Same error..

  6. #6
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Combine multiple rows into one row

    Is there any other way to fix this error.. Mike...

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Combine multiple rows into one row

    If your sure you have 80 columns then try

    Range("a1").Resize(i, 80).Borders.LineStyle = xlContinuous

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Combine multiple rows into one row

    Im not sure why, you can remove that line. All it does is add the border around the data.

  9. #9
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Combine multiple rows into one row

    Mike.. It worked without any error.. Thank you very much for your support.. It is incredible .. U made my day.. Thanks..

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Combine multiple rows into one row

    Could try this and see if it would work..

    Range("a1").Resize(i, UBound(a, 1) + 1).Borders.LineStyle = xlContinuous

  11. #11
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Combine multiple rows into one row

    Same error.. Mike.. No change

+ 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