+ Reply to Thread
Results 1 to 13 of 13

Moving alternate rows of data to column

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Moving alternate rows of data to column

    Hi guys, Im trying to put convert an initial N x 1 data, such that, for every 2nd term, it goes to the 2nd column and the 3rd term to the third column. This goes on for the remaining data.

    e.g.

    1
    2
    3
    4
    5
    6
    7
    8
    9

    to become:

    1 2 3
    4 5 6
    7 8 9




    I have this small VBA script:

    Please Login or Register  to view this content.
    However when running this, it gives me instead:

    1 2 3
    3 4 5
    5 6 7
    7 8 9


    Can someone let me know what is wrong with my VBA code?

    Thanks!
    Last edited by Corsa88; 09-11-2015 at 10:32 PM. Reason: Table and code format

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Need help regaring a small VBA macro

    Hi and welcome to the forum.

    Please read the rules here as to format your code correctly.
    also, please tell us your expected outcome.

  3. #3
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Need help regaring a small VBA macro

    Quote Originally Posted by JasperD View Post
    Hi and welcome to the forum.

    Please read the rules here as to format your code correctly.
    also, please tell us your expected outcome.
    Hi Jasper

    Thank you for the reply, have formatted my code according to the guide.

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Need help regaring a small VBA macro

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Need help regaring a small VBA macro

    Quote Originally Posted by JasperD View Post
    Please Login or Register  to view this content.
    Hi Jasper

    Thanks for the solution!

    Would there a more general way of getting the range of 'a' ? I might possibly have data spanning greater than 9 rows (likely > 100 rows of data), manual input might be too cumbersome.

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Need help regaring a small VBA macro

    You can put anything you want on the line where a is specified.

    Please Login or Register  to view this content.
    for example, all cells in column A:
    Please Login or Register  to view this content.
    shouldn't be too hard.
    Please click the * below if this helps

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

    Cool Hi ! Try this demonstration ‼


    Another way :

    PHP Code: 
    Sub Demo()
        
    With Cells(1).CurrentRegion:  VA = .Value:  .Clear:  End With

        With Cells
    (1).Resize(UBound(VA) / 33)
            For 
    N& = 1 To UBound(VA):  .Cells(N).Value VA(N1):  Next
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 09-11-2015 at 08:22 PM. Reason: optimization …

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

    Lightbulb Try this !


    A full array way :

    PHP Code: 
    Sub Demo2()
        
    With Cells(1).CurrentRegion:  AR = .Value:  .Clear:  End With
        C 
    = Array(312):   N& = UBound(AR) \ 3:   R& = 1
        ReDim VA
    (1 To N - (UBound(AR) > 3), 1 To 3)
        For 
    1 To UBound(AR):  M% = N Mod 3:  VA(RC(M)) = AR(N1):  - (0):  Next
        Cells
    (1).Resize(UBound(VA), 3).Value VA
    End Sub 
    Thanks for the rep' !
    Last edited by Marc L; 09-11-2015 at 09:12 PM.

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Need help regaring a small VBA macro

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem - not what you think the answer might be. (think google search terms?). Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the address bar)

    Many members search our previous posts, and thread titles play a big part of the search. I doubt anybody would do a search based on your title?

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (note: this change is not optional )
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  10. #10
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Try this !

    Quote Originally Posted by Marc L View Post

    A full array way :

    PHP Code: 
    Sub Demo2()
        
    With Cells(1).CurrentRegion:  AR = .Value:  .Clear:  End With
        C 
    = Array(312):   N& = UBound(AR) \ 3:   R& = 1
        ReDim VA
    (1 To N - (UBound(AR) > 3), 1 To 3)
        For 
    1 To UBound(AR):  M% = N Mod 3:  VA(RC(M)) = AR(N1):  - (0):  Next
        Cells
    (1).Resize(UBound(VA), 3).Value VA
    End Sub 
    Thanks for the rep' !
    Ah, may i know what is the difference between this and the previous one? Both seem to work well with large data

  11. #11
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Need help regaring a small VBA macro

    Quote Originally Posted by FDibbins View Post
    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem - not what you think the answer might be. (think google search terms?). Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the address bar)

    Many members search our previous posts, and thread titles play a big part of the search. I doubt anybody would do a search based on your title?

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (note: this change is not optional )
    Sure, I made a change to the title. Do see if the title description is adequate?

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

    Arrow Re: Try this !

    Quote Originally Posted by Corsa88 View Post
    Ah, may i know what is the difference between this and the previous one?
    Both seem to work well with large data
    Demo2 could be faster with large data (writes cells range at once)
    'cause first Demo has not display off (see ScreenUpdating property) and writes a cell by a cell …
    Last edited by Marc L; 09-12-2015 at 07:22 AM. Reason: typo …

  13. #13
    Registered User
    Join Date
    02-20-2014
    Location
    SG
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: Try this !

    Quote Originally Posted by Marc L View Post
    Demo2 could be faster with large data (writes cells range at once)
    'cause first Demo has not display off (see ScreenUpdating property) and writes a cell by a cell …
    I see, that has been extremely helpful. Many thanks Marc !

+ 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 Small Function works when small(array,1),small(array,2) are same ?
    By bkvenkat in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-02-2015, 02:00 AM
  2. [SOLVED] Small macro need to modify
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-12-2013, 11:16 AM
  3. Functions similar to SMALL or overcome limitations of SMALL
    By arvindtechie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-05-2013, 10:59 AM
  4. Need to optimize the small macro
    By Carnifex930 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-11-2011, 09:00 PM
  5. need small help with a macro please
    By excelguru in forum Excel General
    Replies: 3
    Last Post: 11-13-2006, 12:22 AM
  6. Small Macro
    By tbobo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2006, 01:40 PM
  7. Newbee needs HELP-Small Macro
    By tbobo in forum Excel General
    Replies: 4
    Last Post: 03-08-2006, 03: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