+ Reply to Thread
Results 1 to 6 of 6

'Loop Until' Problem

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    25

    'Loop Until' Problem

    Having issues with the below 'Do....Loop Until' not stopping when the data stops.

    In the sample attached there are only three rows of data but the code keeps looping for a long time. I've tried a few different combinations of 'Do While' and 'Loop Until' and just can't figure it out. Any suggestions will be greatly appreciated.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: 'Loop Until' Problem

    Hi,

    You are testing for a range which always exists, even though the cells defined by the range are blanks.

    Instead end your loop with

    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: 'Loop Until' Problem

    Iwasiw35,

    Alternate coding method:
    Please Login or Register  to view this content.
    Last edited by tigeravatar; 11-08-2011 at 07:45 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: 'Loop Until' Problem

    What, exactly is this routine doing?

    You set myrng as a number of cells on row 1. Then you offset down the page.

    I don't think myrng will ever be "nothing", it's always going to be a group of cells.

    You'd be better establishing the last row of data and then counting down to that ... if that's what you're trying to do.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: 'Loop Until' Problem

    Iwasiw35,

    The end goal can also be accomplished with a formula. In Cell A1:
    =INDEX($C1:$Z1,,LOOKUP(2,1/(ISNUMBER(SEARCH(CHOOSE(COLUMN(),"p","f")&"a01",$C1:$Z1))),COLUMN($C1:$Z1)-2)-6)

    Then copy to cell B1 and drag both down
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-07-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: 'Loop Until' Problem

    Thanks for the suggestions everyone. I tried Richard's method (he got in first) and it worked a treat. Good lesson for the future.

+ 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