+ Reply to Thread
Results 1 to 18 of 18

Transpose every 4 rows in one column to 4 column in one row

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    San Jose, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Transpose every 4 rows in one column to 4 column in one row

    Hello,

    Please help to create a Marco in which transpose data from every 4 rows in one column to 4 columns in the one row. Since there are so many data (5000+) so I think Macro will be helpful to sort this out. Please refer to the the attachment for sample data and expected output.

    Many thanks in advance.
    -Lena
    Attached Files Attached Files

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Transpose every 4 rows in one column to 4 column in one row

    Hi Lena,

    Not a very pretty solution, but it works. Add a worksheet named "Result" to your workbook and add the code below to a module and run.

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Transpose every 4 rows in one column to 4 column in one row

    Or a shorter version, using copy & paste with transpose

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Transpose every 4 rows in one column to 4 column in one row

    And an even shorter one, which doesn't use looping, so is likely to be much faster

    Please Login or Register  to view this content.

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

    Re: Transpose every 4 rows in one column to 4 column in one row

    As an option

    Please Login or Register  to view this content.

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Transpose every 4 rows in one column to 4 column in one row

    Quote Originally Posted by Andrew-R View Post
    And an even shorter one, which doesn't use looping, so is likely to be much faster
    I am sure it is, but honestly I cannot make head or tails from it. I still have a lot to learn

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Transpose every 4 rows in one column to 4 column in one row

    Quote Originally Posted by OllieB View Post
    I am sure it is, but honestly I cannot make head or tails from it. I still have a lot to learn
    Well if we were trying to solve this problem with formula we could use:

    =OFFSET($A$2,(ROW()-2)*4+COLUMN()-3,0)

    Because all of the cells would have the exact same formula in we can use a macro to write the formula to all of the cells at once, calculate the result and then replace the formula with the value it returns.

    I couldn't have done this when I joined this forum, 2 and a bit years ago, but it's a great place to learn new Excel skills

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Transpose every 4 rows in one column to 4 column in one row

    Quote Originally Posted by Andrew-R View Post
    Well if we were trying to solve this problem with formula we could use:
    Andrew, thanks for the explanation. Very interesting approach. I tend to use basic VBA for every problem, and sometimes forget that Excel offers more than just an environment to write VBA solutions in.

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

    Re: Transpose every 4 rows in one column to 4 column in one row

    Yet another

    Please Login or Register  to view this content.
    Thanks,
    Mike

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

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Transpose every 4 rows in one column to 4 column in one row

    Mike,

    Is it really necessary to use the With clause?

    Please Login or Register  to view this content.
    or would the following also work, since we seem to be striving for short code

    Please Login or Register  to view this content.

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Transpose every 4 rows in one column to 4 column in one row

    Is it necessary to use VBa?

    Try this in C2, Drag Across to F2, then Down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

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

    Re: Transpose every 4 rows in one column to 4 column in one row

    @Marcol

    Yeap that works for me.

    @OllieB

    No not really necessary, just personal preference

  13. #13
    Registered User
    Join Date
    10-18-2012
    Location
    San Jose, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Transpose every 4 rows in one column to 4 column in one row

    Yeap It works! Wow it's amazing, you all are super VBA coding and Excel expert! Thank you so much for your all your help Mike, Marcol, OllieB, Andrew, AB33. I'm new vba and I still learn it.
    Thanks again
    -Lena

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Transpose every 4 rows in one column to 4 column in one row

    On behalf of all, happy to have helped ...

  15. #15
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Transpose every 4 rows in one column to 4 column in one row

    Hello,

    Can you please attach the excel workbook with thr working vba?

    Thank you

  16. #16
    Registered User
    Join Date
    11-07-2013
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Transpose every 4 rows in one column to 4 column in one row

    Hello - I have a very similar question and I was wondering if anyone could assist. I have a range of values in one tab called "Debt" and I want to tranpose the data into rows starting in cell C2 on my "Statatest" tab. However, I would like to paste the data on every fifth row. I cannot figure out how to do this my current code only pastes and transposes to one row. In all, I have five worksheets with data I want to copy and transpose to the Statatest tab. Any thoughts are greatly appreciated?

    Here is my code:

    Please Login or Register  to view this content.
    Last edited by arlu1201; 11-07-2013 at 01:41 PM.

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

    Re: Transpose every 4 rows in one column to 4 column in one row

    Cog38,
    Welcome to the forum.
    Please read forum's rule.
    You need to start your own thread.

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Transpose every 4 rows in one column to 4 column in one row

    Thanks AB33.

    Also cog38,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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