+ Reply to Thread
Results 1 to 11 of 11

Help with vba macro crash

  1. #1
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Help with vba macro crash

    Hello, everyone!

    I've just written a hefty piece of vba code and while it works like a charm it keeps crashing for no known by me reason. Since this is important to me and I am a complete newbie to vba I would like to ask for your help solving this problem.

    The macro itself is basically a huge If/then/else cycle that checks what's the value in a cell and fills other cells, based on the value.

    Since the code itself is more than 10000 characters long, I will write the last subroutine in the following post. There's a commented section I've left in on purpose, just in case.

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: Help with vba macro crash

    Last subroutine.

    I can tell the entire thing works, because it fills the correct values and a second after excel just closes itself, just like that.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with vba macro crash

    Does the code break?

    Is all the code in the sheet module? Everything except the Change event should be in a standard module.

    I think Multiclass could be replaced with something like this:

    Please Login or Register  to view this content.
    ... and the other code could be similarly simplified.
    Last edited by shg; 09-01-2012 at 02:53 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: Help with vba macro crash

    I am not sure what it means for the code to "break", but if you mean whether or not it displays some sort of error/warning, then - no, it runs flawlessly, executes to the end and then excel just closes.

    Actually I've put all the code on one sheet (Sheet1) is that a problem?

    And thank you, that looks much simpler, I didn't know the .find method even existed before this. :D
    I shall rewrite it and see what happens.

    EDIT: OK, so I've rewritten the subroutines "References" and "Multiclass", at first they both worked fine but when I basically ran the third "if" from the "Worksheet_Change" sub it began to crash every time I used any of the subs, afterwards.

    Please Login or Register  to view this content.
    Last edited by Durarara; 09-02-2012 at 06:23 AM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with vba macro crash

    Actually I've put all the code on one sheet (Sheet1) is that a problem?
    Put the change event code in the sheet module and everyhing else in a standard module.

  6. #6
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: Help with vba macro crash

    Nope, does not help at all. In all three cases where the subs are executed excel crashes.

    Just by the way - is it wrong to have them all in one sheet?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with vba macro crash

    When you say "crash", you mean Excel closes?

  8. #8
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: Help with vba macro crash

    Yes, I thought I have mentioned that?

    I can tell the entire thing works, because it fills the correct values and a second after excel just closes itself, just like that.
    I am not sure what it means for the code to "break", but if you mean whether or not it displays some sort of error/warning, then - no, it runs flawlessly, executes to the end and then excel just closes.
    I am not sure if it matters, but I would like to stress that it DOES execute to the end and AFTER it closes. Although I am not sure if that's because the problem is within the end of the procedure of whether it is processor lag.
    Last edited by Durarara; 09-02-2012 at 05:38 PM.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with vba macro crash

    By code breaking, I mean it stops executing and the VBE takes you to the code with the offending line highlighted (or gives you the option of doing so if you select Debug).

    You say your code runs to the end; how do you know that?

    You could set several breakpoints in your code, including at the last line (End Sub) of the Change event; if you don't get there, it didn't finish executing. In VBE options, you could set error handling to break on all errors.

    I do note that you have a long If/ElseIf statement to set ranges, but nothing to test that they are actually set (there is no Else clause).

    If you're not already familiar, now would be a good time to read http://www.cpearson.com/excel/debug.htm

  10. #10
    Registered User
    Join Date
    07-22-2012
    Location
    The Shire
    MS-Off Ver
    Office 2013
    Posts
    51

    Re: Help with vba macro crash

    Oh, My God, it is so simple... it always is, isn't it?

    I've just read the link you gave me, many thanks for that, and started debugging line by line and guess what? My "Reference" subroutine? I hadn't disabled "Application.EnableEvents" when I told it to change a bunch of values in the sheet with the "change event" macro. Even though it didn't change any of the cells that the "ifs" filter, I guess it caused a memory overflow or something similar and Excel closes itself.

    Hah, silly. Thank you for helping me find my error!

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Help with vba macro crash

    You're welcome.

    There is nothing, nothing that will improve your coding skill like debugging your own code.

+ 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