+ Reply to Thread
Results 1 to 23 of 23

Arrange horizontal data to vertical through cut, paste, loop

  1. #1
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Arrange horizontal data to vertical through cut, paste, loop

    I have some data that is arranged horizontally in rows that repeats the same type of data every 4 rows. It is repeated 12 times per row. I want to arrange the data vertically. So I want to identify the last row in the workbook, currently row 59 (although that will change everytime I add data). Select AW:59-AZ:59 and insert into E:60-H:60. Cut the next set of data: AS:59-AV:59 and insert into E:61-H:61. Etc. repeated until the data has been cut from I:59-L:59 and pasted into E:70-H70. Then I will need to loop the whole thing and do it in row 58, etc until I get to row 1. Row 1 contains headings and not data.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Please attach a workbook, showing clearly what your current structure looks like, and what your required outcome looks like. Please be clear about the required sort order of the final data, as there will be more than one way of looping through and transferring data to columns...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    I have included a truncated form of the original. The number of rows will vary.
    I also uploaded a form in which I did the cutting and pasting for the bottom two rows as an example of how I would like this to be done.
    Attached Files Attached Files

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Are you really happy leaving A:D blank? Would it not be better to include the correct values in A:D for every row?

    Is the order of the outcome essential (ie - reverse column order)? Because while it's possible to loop through the way you describe, it's probably more efficient to cut and paste larger blocks of text at a time.

  5. #5
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Ideally, I would like for A:D to be filled with the data. It would be best as you suggest, but I didn't know if that was possible. The order of the columns is not important. However, the alignment of the data under the correct heading is imperative. For example. Data that begins in AW (column heading Word . . . ) will need to be pasted in column E (column heading Word . . .).

    Data cut from row 2 will always need to have the associated Record ID, Exposure, Dose, and Dose Frequency as originally assigned. So any data from row 2 would need to have: Record ID=KAW007, Exposure=6, Dose=6, Dose Freq=1. However, the order of the columns or rows is not important as long as the data remains consistent with its original column heading, and original A:D entries.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Okay. Here's a loop of code that does exactly what you initially asked for, but a bit slowly:
    Please Login or Register  to view this content.


    Now here's another better solution, which works much faster, and includes data in A:D:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Thanks, but I get a run-time error:

    Method 'Range' of object'_Worksheet' failed.

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Quote Originally Posted by kcheeser View Post
    Thanks, but I get a run-time error:

    Method 'Range' of object'_Worksheet' failed.
    Which subroutine, which line? Are you trying it on the workbook "original data"?

  9. #9
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Last line of each sub. Yes, I tried it on the "original data".

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Last line?

    Please Login or Register  to view this content.
    ??

  11. #11
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    ".Range(Cells(1, 9), Cells(1, lColMax)).Clear"

  12. #12
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    No idea. I can't replicate your error.

    The code worked perfectly on my XL2010 machine when I wrote it this afternoon, and is working perfectly on my XL2013 machine now: Just downloaded your "original data" file, pasted the 'bar' code into a new module, and it ran perfectly.


  13. #13
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Let me fiddle around with it and see what is going on. I'm also using 2013

  14. #14
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    There should be no fiddling needed. Apply that code to the workbook you uploaded, and it should work with no issues. Unless you've changed something.

  15. #15
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    I don't get it. I haven't changed a thing, and I can't get it to work. Still same error code.

  16. #16
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Odd. I've asked if others can take a look, see if they get the same error and / or if I'm missing something!

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Please upload the wb with the code already in place.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  18. #18
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Both macros run w/2007
    Ben Van Johnson

  19. #19
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Hooray. I just tried it on a different computer and it worked beautifully. I will try to see what is going on with the settings on the other computer. Thanks SO much for your help.

  20. #20
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Quote Originally Posted by protonLeah View Post
    Both macros run w/2007
    Thanks for testing

    Glad it's working for you now, kcheeser. Now, see if you can understand how the code actually works, so you can adapt it as and when necessary!

  21. #21
    Registered User
    Join Date
    09-20-2013
    Location
    Lawrence, Kansas
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Arrange horizontal data to vertical through cut, paste, loop

    I will. I'm always learning. Thanks again.

  22. #22
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Arrange horizontal data to vertical through cut, paste, loop

    If Sheet1 is not active sheet that code will fail. It is better to write:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  23. #23
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Arrange horizontal data to vertical through cut, paste, loop

    Quote Originally Posted by Izandol View Post
    If Sheet1 is not active sheet that code will fail. It is better to write:
    Please Login or Register  to view this content.
    THAT'S what I was missing. Oops!

    Thanks, Izandol.

+ 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. How to arrange vertical Vcards column into horizontal rows ?
    By m.rizeg in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 07-26-2013, 10:00 PM
  2. [SOLVED] Horizontal then Vertical Loop help
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2013, 09:56 AM
  3. [SOLVED] how to arrange slicer look from vertical to horizontal?
    By koi in forum Excel General
    Replies: 1
    Last Post: 10-29-2012, 03:39 AM
  4. Transpose horizontal data to vertical data with paste link
    By M.Devadhasan in forum Excel General
    Replies: 0
    Last Post: 07-07-2012, 01:01 PM
  5. Arrange vertical string into multiple horizontal columns
    By tribalgifts in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-17-2009, 02:20 AM

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