+ Reply to Thread
Results 1 to 6 of 6

Sub behiving different with different trigger type

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Sub behiving different with different trigger type

    I have a Worksheet_Change that crashes when the user manually changes a cell value, but doesn't crash if a macro changes the cell value.

    I have a cell (Range("SelectMtg")) with Data Validation:List. When a selection is made the Worksheet_Change() checks to see if the data has been saved and if it's saved it then copies the Target.Value into another cell (Range("MtgSelected")). If the data hasn't been saved it reverts Target.Value back to it's prior value.

    I also have a Form Button on the sheet that runs a macro that locates the next Mtg in the list and replaces .Range("SelectMtg") with the next Mtg.

    During normal data entry the button is used to set up the next Mtg, but the dropdown picklist allows the user to select a specific Mtg when necessary. This system has been working for a few months with no problem.

    Now today the Sub crashes with an error code 1004 "Application or Object-Defined Error".
    But only if the user changed the value manually by picking from the dropdown. If the user clicks the button it works fine.

    This file is not mine to post but here a simplified version of Worksheet_Change().

    Please Login or Register  to view this content.
    The macro attached to the button is basically this
    Please Login or Register  to view this content.
    Is there some reason that a sub would crash when the user changes a value, but doesn't crash when a different sub changes the value?
    Last edited by foxguy; 10-19-2011 at 03:44 PM.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sub behiving different with different trigger type

    Hello foxguy,

    The worksheet change event will fire each time a cell value is changed on the worksheet. This will cause a cascade stack overflow. You need to stop Excel from responding to events until your macro in the change event has finished. You can do this using the Application.EnableEvents method. Set the value to false before your macro runs and then set it back to true before you exit the macro.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Sub behiving different with different trigger type

    Leith;
    You're right, but that's not my problem.

    I overlooked putting in my post. I was typing it in the thread and leaving out all the stuff that doesn't affect anything, and didn't realize I left out the EnableEvents=False
    I put it in MtgButton by mistake.
    I'm editing my post to reflect the reality.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sub behiving different with different trigger type

    Hello foxguy,

    Chan eil mi 'gad thuigsinn.

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Sub behiving different with different trigger type

    I found what was causing the problem, although I have no idea how or why.
    I have been playing around trying to create a Non Volatile Dynamic Range Name that allows the range to be Cut & Pasted. http://www.excelforum.com/excel-work...mic-range.html. The only way I have discovered is to put a UDF() in the Range Name. Since that was the only thing I had changed in the workbook, I decided to get rid of all of the Range Names with a UDF() in the RefersTo, and my problem went away.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sub behiving different with different trigger type

    Hello foxguy,

    Glad to know you got it sorted out. Thanks for sharing your findings.

+ 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