+ Reply to Thread
Results 1 to 5 of 5

Excel Crash On Second Loop in Macro

  1. #1
    Registered User
    Join Date
    04-22-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Excel Crash On Second Loop in Macro

    I am trying to finish my macro for work (can't necessarily post a workbook that this would be working on due to confidentiality agreements and such). The macro runs correctly for one full loop and almost to the formatting portion of the second loop, but then causes excel to crash. I do not know if the computer that I am working on has insufficient memory (3GB, so should not be a problem) for this code or if there is anything that I can do to decrease the load that this causes. I know this may not be the most efficient way to write this code, but is how I found to get it to work up to this point (mostly testing by ending the loop at the end of the first run through).

    This code also calls a userform that I am passing the variable lstChoice through (userform used to select options via radio buttons). The variable lstChoice can be assigned integers from 0 to 4 via the userform.

    Any help would be greatly appreciated.

    ::Note:: I have attached the code in a text file due to character limit.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-15-2010
    Location
    Everett, WA
    MS-Off Ver
    All versions; most components
    Posts
    188

    Re: Excel Crash On Second Loop in Macro

    Not sure exactly what is causing your failure, but I see some general room for improvement. First, you don't typically need to Select sheets or cells; if you know their names or addresses, just use those followed by the operation you wish to perform, instead of using the address to select and then operating on active or selected cells/sheets. Second, you can move all of your Dim statements above the loop. If each variable will not always be overwritten in subsequent loops, you can set them to null or 0, etc. depending on data type, at the top of each loop iteration (where you're currently dimming them all again). Perhaps most importantly, you should set calculation to manual and turn of screen updating. Currently, Excel is trying to redraw/recalculate over and over throughout your loop; MAJOR resource hog.

    Please Login or Register  to view this content.
    Warning, though, if you are the only one running this macro, you are probably safe to use the above method. However, if you are distributing this workbook, I'd recommend capturing the user's settings first, so you can set back on completion. Something like:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-22-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Excel Crash On Second Loop in Macro

    Thank you very much for the help, I will check these suggestions out next week and let you know how it goes.

  4. #4
    Registered User
    Join Date
    04-22-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Excel Crash On Second Loop in Macro

    I am still getting crashing after applying the previously mentioned fixes. I have been able to find the problematic area though. It seems to be crashing in the else portion of the first if then statement following the commented line 'create scatter plot. This is starting at line 337 in the text file attached. Does anyone have any other suggestions/input?

  5. #5
    Registered User
    Join Date
    04-22-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Excel Crash On Second Loop in Macro

    Update:

    It seems that the userform that I was using had been causing the crash. If I comment out the userform (formControlType) lines and make the choice manually in the code, then everything runs as expected. Does anyone know why this is happening? I would prefer the use of radio buttons to select my choices, but may not have the option if the userform is crashing my macro.

    Also, is it possible to, when looping through the worksheets, start on the currently selected worksheet?

+ 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