+ Reply to Thread
Results 1 to 6 of 6

Do Until loop not ending

  1. #1
    Registered User
    Join Date
    03-07-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007/2010, Outlook 2007/2010
    Posts
    60

    Do Until loop not ending

    The attached document has the problem. I have several problems with this spreadsheet and the VBA I'm building into it, but I hope with this one question answered I may continue. In the sheet JAN I have Button 8 and a macro it runs. The macro of this button should loop through every row in the Alex column and sum each heading (Hours, CC pledges, CC amounts, etc. through Not Home) to its place in the first 12 rows for Alex. It works for the first header (Hours) but then doesn't work for any of the other header types - it gets caught looping infinitely.

    Call Report.xlsm

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Do Until loop not ending

    you start with FunctionRow = 3 then open the loop with Do Until FunctionRow = 13 then you increment the value by 23
    FunctionRow = FunctionRow + 23
    How can the loop end ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,438

    Re: Do Until loop not ending

    One of the debugging tools I use most often is the "set a breakpoint and step through code" (discussion of debugging stratigies: http://office.microsoft.com/en-us/su...819.aspx?CTT=1). I would strongly suggest you become familiar with this strategy.

    Following the variable Functionrow (which controls when the outer loop should end) I see:

    Function row = 3
    enter outer loop -- check if function row = 13
    It does not, so execute the loop
    Inside the loop, 23 is added to function row (functionrow=26)
    Continue inner loop (adding 23 each time)
    When it gets back to checking functionrow=13, functionrow=717. still false, so continue executing
    It seems that functionrow would never be equal to 13, so the loop never ends.

    I'm not sure exactly what you are trying to do here, so I would suggest you review your logic and flow control (specifically, how you are manipulating functionrow) and see what you need to do to get it to increment up to 13 rather than skipping over 13.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    03-07-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007/2010, Outlook 2007/2010
    Posts
    60

    Re: Do Until loop not ending

    I see what you mean. Further down in the code I have FunctionRow = FunctionRow + 1 in order to iterate to the next type (hours, CC Pledges, etc.). Should I have 2 different variables, then, one to move by 23 lines to jump from one date to the next and another to reset to the next header type?

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,438

    Re: Do Until loop not ending

    Adding another counter variable does seem like one possible solution.

  6. #6
    Registered User
    Join Date
    03-07-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007/2010, Outlook 2007/2010
    Posts
    60

    Re: Do Until loop not ending

    SOLVED - thank you all!

    The top declaration now reads
    DateRow = 24
    TotalSum = 0
    TestDate = CDate(Cells(DateRow, 2))
    PrintRow = 3
    FunctionRow = PrintRow + 23

    At the end of the loop the following is performed
    PrintRow = PrintRow + 1
    DateRow = 24
    TestDate = CDate(Cells(DateRow, 2))
    TotalSum = 0

    PrintRow has thus become the macro counter and controls FunctionRow, the micro counter.

+ 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. Do until Loop not ending
    By Alexm963 in forum Word Programming / VBA / Macros
    Replies: 6
    Last Post: 12-28-2012, 05:09 PM
  2. [SOLVED] ending a sub FOR loop in a main FOR loop
    By samkumar in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2012, 05:35 AM
  3. [SOLVED] Help with a VBA macro ending with a LOOP
    By 5h1l in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-31-2012, 09:58 AM
  4. Ending a Loop
    By kirsty in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-25-2010, 01:11 PM
  5. Never ending loop
    By Theodjinn in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-23-2008, 04:08 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