+ Reply to Thread
Results 1 to 4 of 4

Transpose Rows to Columns but Keeping Data in Blocks

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    Warwickshire, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Transpose Rows to Columns but Keeping Data in Blocks

    Hi,

    As the title says but I have shown an example below. I need to be able to do this for 106 sets of data each set containing 18 rows. Therefore the output will be 18 rows and 106 columns.

    Thank you very much for you help.

    1
    2
    3
    4
    5
    
    2
    4
    6
    8
    10
    
    3
    6
    9
    12
    15
    
    into 
    
    1      2      3
    2      4      6
    3      6      9
    4      8     12
    5     10     15
    Last edited by james_ross; 01-31-2013 at 09:04 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Transpose Rows to Columns but Keeping Data in Blocks

    Hi,

    try running this macro. I assumed that you only have data in column A.
    Sub ReorgData()
    
    Dim i As Long
    Dim Lr As Long 'last row
    Dim Lc As Long 'last column
    Dim MyRow As Long 'row to copy to
    
    Lr = Range("A" & Rows.Count).End(xlUp).Row
    MyRow = 1
    Range("B1").Value = "x"
    
    For i = 1 To Lr
        Lc = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
        If Range("A" & i) <> "" Then
            ActiveSheet.Cells(MyRow, Lc).Value = Range("A" & i).Value
            MyRow = MyRow + 1
        Else
            ActiveSheet.Cells(1, Lc + 1).Value = "x"
            MyRow = 1
        End If
    Next i
    
    MsgBox "column A not deleted for comparison"
    
    End Sub

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Transpose Rows to Columns but Keeping Data in Blocks

    or
    Sub ert()
    Dim r As Range, i&
    For Each r In Range("A1", Cells(Rows.Count, 1).End(xlUp)).SpecialCells(2).Areas
        i = i + 1: Cells(1, i).Resize(r.Count).Value = r.Value
        If i > 1 Then r.ClearContents
    Next r
    End Sub

  4. #4
    Registered User
    Join Date
    01-07-2013
    Location
    Warwickshire, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Transpose Rows to Columns but Keeping Data in Blocks

    They both work perfectly.

    Thank you very much.

+ 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