+ Reply to Thread
Results 1 to 24 of 24

Transpose rows to columns in large data set

Hybrid View

Larne-O Transpose rows to columns in... 03-28-2013, 04:40 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 04:50 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 05:10 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 05:28 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 05:34 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 05:47 AM
zalora Re: Transpose rows to columns... 03-28-2013, 05:53 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 06:07 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 06:12 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 06:14 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 06:23 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 06:56 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 06:50 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 07:07 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 07:13 AM
zalora Re: Transpose rows to columns... 03-28-2013, 08:12 AM
Larne-O Re: Transpose rows to columns... 03-28-2013, 10:48 AM
AB33 Re: Transpose rows to columns... 03-28-2013, 12:13 PM
zalora Re: Transpose rows to columns... 03-28-2013, 12:47 PM
AB33 Re: Transpose rows to columns... 03-28-2013, 12:50 PM
zalora Re: Transpose rows to columns... 03-28-2013, 12:57 PM
zalora Re: Transpose rows to columns... 03-28-2013, 12:56 PM
Larne-O Re: Transpose rows to columns... 04-02-2013, 04:39 AM
zalora Re: Transpose rows to columns... 04-03-2013, 04:04 AM
  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Transpose rows to columns in large data set

    Hello,
    I tried different macros that I found here on the forum for transposing rows to columns, but I can't make them work. I don't know anything about macros why I cannot decode them. My data set have 145 columns and almost 45000 rows..
    Appreciate any help I can get!
    BR
    Last edited by Larne-O; 04-02-2013 at 10:09 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    It may be possible, but we need a sample. One sheet should shows the data as it is now and the second sheet -the desired result-output, but all should be in one single book. To attach a sample, go to advance then attachment.

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    I added a file containing the first ten rows. Is that enough? The whole data sheet is too large to attach.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Fine!
    Sheet1 is the raw data and sheet2 is the output. Am I right?

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    Yes it is : )

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Output in sheet 3
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    you can try this
    Sub test()
    Dim lastrow As Long
    Dim lastcolumn As Long
    Dim initialrow As Long
    Dim initialcolumn As Long
    lastcolumn = 1
    lastrow = 1
    initialrow = 1
    initialcolumn = 1
    While Cells(lastrow, lastcolumn).Value <> ""
        While Cells(lastrow, lastcolumn).Value <> ""
            lastcolumn = lastcolumn + 1
        Wend
        lastrow = lastrow + 1
    Wend
    While initialcolumn <> lastrow
        While initialrow <> lastcolumn
            Cells(initialrow & initialcolumn).Copy (Worksheets("Sheet2").Cells(initialcolumn & initialrow))
            initialrow = initialrow + 1
        Wend
        initialcolumn = initialcolumn + 1
    Wend
    End Sub

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Another option

    Sub trans()
    Dim x, y(), i&, j&, k&, t&
    x = Sheets("Sheet1").Range("A2").CurrentRegion.Value
    ReDim y(1 To UBound(x, 1) * UBound(x, 2), 1 To UBound(x, 2))
    
    For i = 1 To UBound(x, 1)
       k = k + 1
       y(1, k) = x(i, 1)
    Next
    
    t = 0
    For i = 1 To UBound(x, 1)
    
    k = 1
    t = t + 1
        For j = 2 To UBound(x, 2)
            k = k + 1
              
              y(k, t) = x(i, j)
        Next j
    Next i
    
    With Sheets("Sheet3")
        .UsedRange.ClearContents
        .Range("A1").Resize(k, UBound(x, 2)).Value = y()
        .Activate
    End With
    End Sub

  9. #9
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    Nothing happened when I tried you macro zalora. Any suggestions?

  10. #10
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    I tried your macro AB33 and I get an error message: Run time error 7: Out of memory.
    Is there a solution?

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Larne-O,
    I have given you two different codes. one of the code was attached with the sample. I do not believe there is any issue of speed with both, not specially with the second one.
    In which line of the code do you get the error- highlighted in yellow?

  12. #12
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    The other macro you send to me is marked yellow at:
    ReDim y(1 To UBound(x, 1) * UBound(x, 2), 1 To UBound(x, 2))
    It is this one that gives the run time error message.

  13. #13
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    I'm sorry AB33 I did not see the first one. It makes it in the example file, but when I try it in my file it does not. Then I first get a Compile Error: Expected End Sum. The yellow mark is over the first row in the code: Sub columnstocol()

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Larne-o,
    Your actual data must be different to the sample attached. This is normal, do not worry, we will find round it.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Larne-o,
    sent you a private message, need to check your messages

  16. #16
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    sorry about that code, just now i am rush time,Now it is the fix code

    Sub test()
    Dim lastrow As Long
    Dim lastcolumn As Long
    Dim initialrow As Long
    Dim initialcolumn As Long
    lastcolumn = 1
    lastrow = 1
    initialrow = 1
    initialcolumn = 1
    
    While Worksheets("Sheet1").Cells(lastrow, 1).Value <> ""
        lastrow = lastrow + 1
    Wend
    While Worksheets("Sheet1").Cells(1, lastcolumn).Value <> ""
        lastcolumn = lastcolumn + 1
            
    Wend
     While initialrow <> lastrow
            initialcolumn = 1
            While initialcolumn <> lastcolumn
                Worksheets("Sheet1").Cells(initialrow, initialcolumn).Copy (Worksheets("Sheet2").Cells(initialcolumn, initialrow))
                initialcolumn = initialcolumn + 1
            Wend
          initialrow = initialrow + 1
     Wend
    
    End Sub
    Last edited by zalora; 03-28-2013 at 08:18 AM. Reason: type wrong

  17. #17
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    ok, it was fine, but it only copied to the next sheet which is not broad enough to fit all columns. I guess the transposed data has to be in several sheets?

  18. #18
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Olivia,
    I know now what the issue is: Size of excel

    1,048,576 rows by 16,384 columns

    I though I was gone mad, I did not realise I could not transpose more than 16384 rows in to columns. I have tested my code with exact figure of maximum limit of 16,384 and I then added one more row that 16385, my code then fails.
    So, I do not know what do you want me to do. One option would be to break the data in to maximum limit and transpose it. I do not know if this what you wanted to do. Try it yourself by putting a maximum row of 16384 in a sheet and run my code.

  19. #19
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    if you want copy to other sheet just add

    While initialrow <> lastrow
            initialcolumn = 1
            While initialcolumn <> lastcolumn
                Worksheets("Sheet1").Cells(initialrow, initialcolumn).Copy (Worksheets("Sheet2").Cells(initialcolumn, initialrow))
                Worksheets("source Sheet").Cells(initialrow, initialcolumn).Copy (Worksheets("destination sheet").Cells(initialcolumn, initialrow)) <----paste this more than one time if you wan to paste to other        
                                                                                                                                                                                                  sheet remember change the sheet name
                initialcolumn = initialcolumn + 1
            Wend
          initialrow = initialrow + 1
     Wend

  20. #20
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Transpose rows to columns in large data set

    Zalora,
    The code is not the issue, but the size of OP's data. The data have over 44k rows.

  21. #21
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    Long variables can range from -2,147,483,648 to 2,147,483,647.

  22. #22
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    don't worry about that i use long data type it can contain more 44K number

  23. #23
    Registered User
    Join Date
    03-27-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Transpose rows to columns in large data set

    I'm sorry zalora I'm not good enough to change the code myself, even if I guess it's simple. I thought that the columns wouldn't fit one sheet. That's why I thought they should go into different sheets, is that what you are suggesting?

  24. #24
    Registered User
    Join Date
    03-06-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Transpose rows to columns in large data set

    u means it when reach the certain number will go into another sheet?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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