+ Reply to Thread
Results 1 to 8 of 8

Macro loop not terminating

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2002
    Posts
    8

    Macro loop not terminating

    Hi i have a macro that is supposed to execute everytime something is changed on a sheet other than the summary one. the code is as follows

    Please Login or Register  to view this content.
    The problem is that the code will run and do what its supposed to. But then it won't stop and i have to break it to to unfreeze my excel program. any help?
    Last edited by sachinahj; 07-27-2012 at 01:34 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: why is this not stopping!!

    you are changing worksheet during worksheet change event!

    my untested revision:

    Please Login or Register  to view this content.
    Note: I added enableevents = false at the beginning and True at the end. Also addded ErrorHandler to ensure enableevents is always set back to true.
    Last edited by vandan_tanna; 07-27-2012 at 01:05 PM.
    Regards,
    Vandan

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: why is this not stopping!!

    @ vandan_tanna
    You will need
    Application.EnableEvents = True in your ErrorHandler
    Please Login or Register  to view this content.
    This isn't required
    Please Login or Register  to view this content.
    Last edited by Marcol; 07-27-2012 at 01:21 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: why is this not stopping!!

    Marcol
    if you don't have the errorexit part you'll get an error message every time
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Macro loop not terminating

    @Marcol:

    I like single point exit. This is why in ErrorHandler I just show the error message and then go to ErrorExit where I reset the EnableEvents and exit the sub. For this particular example, only one item (EnableEvents) has to be reset, but in some cases a lot more needs to be reset. With my method, there is just one place - ErrorExit - where you reset everything, and you get to ErrorExit regardless of error! I guess is a matter of preference.

    You solution will work also as long as you add exit sub before ErrorHandler (as JosephP pointed out)

  6. #6
    Registered User
    Join Date
    07-26-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2002
    Posts
    8

    Re: Macro loop not terminating

    Do i have to have an error handle?? I just started VBA this week and Id prefer not to put a debug and error handle into this simple code.

    What if i change the sheetchange to sheetcalculate.. when i do this the macro doesn't execute when i hit cmd + =.

    Any suggestions... Id rather have it on sheet calculate anyway but it wasn't working in the first place so thats why i gave up on that.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro loop not terminating

    why would you want to not handle errors? you can simplify to
    Please Login or Register  to view this content.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro loop not terminating

    Apologies, a bit slap dash there ...
    Another way would be
    Please Login or Register  to view this content.

+ 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