+ Reply to Thread
Results 1 to 9 of 9

correct infinite loop

  1. #1
    Registered User
    Join Date
    07-28-2010
    Location
    Duffield, Va
    MS-Off Ver
    Excel 2007
    Posts
    17

    Question correct infinite loop

    Hello

    I am running a private sub in a worksheet (pasted below)
    In this sub it highlights the colorindex of cells. I had to do this because 2003 only allows 3 conditional formats. This part works fine, but when I try to add and accumulators it gets stuck in an infinte loop. For some reason the for each will not break with any or all of the 4 accumulators. As soon as I take them out it works fine. Any help would be greatly appreciated

    Thank You
    Reece
    Please Login or Register  to view this content.
    Last edited by romperstomper; 07-28-2010 at 09:31 AM. Reason: added code tags

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    re: correct infinite loop

    Please use code tags when posting code.

    Turning events off might help:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    07-28-2010
    Location
    Duffield, Va
    MS-Off Ver
    Excel 2007
    Posts
    17

    re: correct infinite loop

    I tried the turning events of before the for each and reactivating after and no luck

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    re: correct infinite loop

    So the code I posted doesn't work?

    Dom

  5. #5
    Registered User
    Join Date
    07-28-2010
    Location
    Duffield, Va
    MS-Off Ver
    Excel 2007
    Posts
    17

    re: correct infinite loop

    Correct. I am still caught in the infinite loop. The 4 cells that display the results from the counter continually count up from 1. They stop counting when they should but start over at the beginning. This function works perfect if I just comment out the 4 lines that do the accumulations.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    re: correct infinite loop

    When you said you were in an infinite loop I assumed you meant the event code kept executing. If that's not the case a sample workbook would probably help.

    Dom

  7. #7
    Registered User
    Join Date
    07-28-2010
    Location
    Duffield, Va
    MS-Off Ver
    Excel 2007
    Posts
    17

    re: correct infinite loop

    I moved the statement to the top (example below) and the loop breaks finally (after 3 repititions) and finishes all the calculations. Not sure exactly why that worked I was just experimenting but I will take it.

    I wanted to post a sample but the sheets are fed from access databases in remote folders so I could only provide snippets. The looping begins with a button bound to a data refresh all.



    Code

    Please Login or Register  to view this content.

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: correct infinite loop

    My fault, turning events off should have been before this bit, not after it:

    Please Login or Register  to view this content.

    Dom

  9. #9
    Registered User
    Join Date
    07-28-2010
    Location
    Duffield, Va
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: correct infinite loop

    Thank you very much for the help. It is greatly appreciated.


    Reece

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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