+ Reply to Thread
Results 1 to 3 of 3

Multiple rows to single rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-22-2014
    Location
    Indonesia
    MS-Off Ver
    2010
    Posts
    177

    Multiple rows to single rows

    Hello

    I have questions,

    I have code to transpose multiple rows into single rows, it not 100% work,

    Sub splitthem()
    Dim Rng As Range, Dn As Range, ray(), Txt As String, t
    Set Rng = Range(Range("A3"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Not temp = Dn And Dn <> "" Then
            Set temp = Dn
            c = c + 1
        End If
        ReDim Preserve ray(1 To 2, 1 To c)
        ray(1, c) = temp: ray(2, c) = ray(2, c) & " " & Dn.Offset(, 1).Value
    Next Dn
    Range("G1").Resize(c, 2) = Application.Transpose(ray)
    End Sub
    as there are at least two problem:
    1. the result is in single cell separate by comma, i need the result in separate column
    2. the last data not show properly, in example, the letter G is not show up.

    Would be great if you can review what's wrong with the code.

    sample file attached.

    Thank you for the help.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Multiple rows to single rows

    Hi !

    Quote Originally Posted by qiyusi View Post
    1. the result is in single cell separate by comma,
    i need the result in separate column
    Just use TextToColumns method as explained in VBA inner help …

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

    Re: Multiple rows to single rows

    This will work

    Sub splitthem()
     Dim aBefore, i As Long, key, tmp
     
     aBefore = Range("a3", Cells(Rows.Count, 3).End(xlUp))
     With CreateObject("scripting.dictionary")
        For i = 1 To UBound(aBefore)
            If Not .exists(aBefore(i, 1)) And Not IsEmpty(aBefore(i, 1)) Then
                tmp = aBefore(i, 1)
                .Item(tmp) = tmp & "|" & aBefore(i, 3)
            Else
                .Item(tmp) = .Item(tmp) & "|" & aBefore(i, 3)
            End If
        Next
        i = 7
        For Each key In .keys
            tmp = Split(.Item(key), "|")
            Cells(i, "H").Resize(, UBound(tmp) + 1) = tmp
            i = i + 1
        Next
     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.

+ 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. Replies: 1
    Last Post: 04-06-2016, 07:02 AM
  2. Replies: 9
    Last Post: 11-11-2015, 08:19 PM
  3. Replies: 5
    Last Post: 05-25-2013, 07:12 AM
  4. Multiple Rows to Single Rows, Macro?
    By jetta1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2013, 05:33 PM
  5. Replies: 4
    Last Post: 07-03-2012, 08:01 PM
  6. Combining Multiple Rows in to Single Rows
    By Pickle29 in forum Excel General
    Replies: 2
    Last Post: 12-07-2011, 01:05 PM
  7. Replies: 1
    Last Post: 03-18-2009, 04:18 PM

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