+ Reply to Thread
Results 1 to 7 of 7

speeding up a loop

  1. #1
    Registered User
    Join Date
    01-07-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    speeding up a loop

    Can anyone suggest a more efficient way of ordering two columns so that the same values are on the same row?

    column M has 16000 filled cells and column P has up to 50 filled cells, so my loop's really slow. For each cell in col P I need to move it to the p cell adjacent to its match in col M.

    so I want:

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

    to be:

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


    Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: speeding up a loop

    hi, menos, can you post sample workbook showing original data and result you need to get?

  3. #3
    Registered User
    Join Date
    01-07-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: speeding up a loop

    Here it is; sheet "before" is an example of data I have (col A ref's to col M in the code and col B refs to P), sheet "after" is how I want it.
    Also I have discovered an error that I've corrected:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by menos; 07-06-2011 at 06:10 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: speeding up a loop

    Hi

    Try the following
    Please Login or Register  to view this content.
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  5. #5
    Registered User
    Join Date
    01-07-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: speeding up a loop

    Hi Roger, thanks so much, that works a treat! So that I learn, can I check that I have interpreted the code correctly?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    a different angle

    I put the values of column B into column C.
    Than I could use the oneliner:

    Please Login or Register  to view this content.



  7. #7
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: speeding up a loop

    Wow!!

    Pretty cool solution!

+ 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