+ Reply to Thread
Results 1 to 7 of 7

Calling a macro from an event macro. Using nest loops with if statements

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    severn, md
    MS-Off Ver
    Excel 2010
    Posts
    9

    Calling a macro from an event macro. Using nest loops with if statements

    Hey guys,

    I am somewhat competent at VBA coding so I am a little embarrassed by this problem: When I run a macro normally it works but then when I call it during an event macro a variable changes unexpectedly. The whole point of the event is to trigger after each data entry so that the interface is automated and therefore much cooler! Its not an issue with public variable declaration because the event macro uses mostly its own variable and the necessary variables from the other macro are public. My only thought is that during the regular macro data is entered into cells and that might trigger the event macro again but I'm not sure. I've even identified where it jumps by using message boxes but I don't have a clue why it jumps.

    Here are the relevant parts of my event macro:
    Please Login or Register  to view this content.
    Here are the relevant parts of my regular macro ProceedStep2 which is where the error occurs:
    Please Login or Register  to view this content.
    The first message box checking the value of j reads 1 and the second reads 4, when it should be 1 because I have one account inputted. The variables are properly defined and have values set by the macro StoreAccounts. This is part of a complex project interface with about 25 different macros(~1500 lines total) so I don't think posting the whole thing would be a good idea. Also, I know the error has something to do with these parts due to the way I separated the macros. Again it works when I run manually but running by using the event macro causes "j" to jump to 4 for some reason. Please help!!!

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Calling a macro from an event macro. Using nest loops with if statements

    Without seeing all the code, my advice is to put:

    Please Login or Register  to view this content.
    at the very top of the event macro and

    Please Login or Register  to view this content.
    at the very bottom of the event macro
    Gary's Student

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Calling a macro from an event macro. Using nest loops with if statements

    Without seeing all the code, my advice is to put:

    Please Login or Register  to view this content.
    at the very top of the event macro and

    Please Login or Register  to view this content.
    at the very bottom of the event macro

  4. #4
    Registered User
    Join Date
    10-15-2012
    Location
    severn, md
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Calling a macro from an event macro. Using nest loops with if statements

    This is TOTALLY BIZARRE but I tried putting those commands around different sections of the code and nothing worked....I closed out without saving and then reopened and it just magically worked. This doesn't make sense since i have already manipulated code multiple times and closed/reopened and it didn't work. Could this be some sort of excel/file bug????

  5. #5
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Calling a macro from an event macro. Using nest loops with if statements

    You may be correct.

  6. #6
    Registered User
    Join Date
    10-15-2012
    Location
    severn, md
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Calling a macro from an event macro. Using nest loops with if statements

    Oh..actually I looked at it again and disabling events during the other called macros is what worked... Thanks so much! I didn't think that an event macro could be retriggered while executing itself...weird.

  7. #7
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Calling a macro from an event macro. Using nest loops with if statements

    Not only can Events be re-triggered (? miss-triggered ?), its nearly impossible to determine whats going on.

+ 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