+ Reply to Thread
Results 1 to 3 of 3

Run Macro when cell contents change

  1. #1
    Registered User
    Join Date
    02-09-2017
    Location
    UK
    MS-Off Ver
    2019
    Posts
    59

    Run Macro when cell contents change

    Hi All

    I'm after some help on the following please!

    I have a macro which when run checks the contents of the active cell and if the contents matches either "Full Day" or "Half Day" the it will put a value from another cell in the adjacent column. The macro works great when running it direct.

    When I add the code to the sheet change event I keep getting a message that I have run out of resources or excel crashes. I have one sheet change event which records any amendments to the sheet with the code located in the workbook object which I think might be causing the problem, but have no idea how to resolve it (And I need to keep this code). I have attached a sample of my workbook.

    Thanks in advance for any help.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Run Macro when cell contents change

    Workbook not downloaded...

    The error occurs because changing a cell (either interactively or by code) will trigger a Worksheet_Change event. If you are already running code in a Change event then that basically causes a 'Circular Reference' (to use a formula analogy) in code.

    The code changes a cell which raises a Change event which changes a cell which raises a Change event which changes a cell which raise... and so on. Eventually (in less than a second) Excel dies.

    To avoid this, you NEED to turn off event handling so the change to the cell does not raise another event. This is done simply by using
    Please Login or Register  to view this content.
    but you MUST make absolutely sure that any errors are trapped correctly so you can turn Event handling on again, otherwise Excel will be totally unresponsive.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-09-2017
    Location
    UK
    MS-Off Ver
    2019
    Posts
    59

    Re: Run Macro when cell contents change

    many thanks for the tip, works great now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro to copy cell contents then remove substring of contents in new cell - Help
    By three_jeeps in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-25-2015, 01:19 AM
  2. Macro Problem: Copy contents of cell; search for contents in another workbook
    By jfishstik in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-04-2014, 12:11 PM
  3. VBA to Change Cell contents
    By NickWeth in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2013, 09:49 AM
  4. Macro to change cell contents based on another cell in the same row
    By lanos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2012, 10:11 AM
  5. [SOLVED] change cell contents
    By Mary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2005, 07:05 PM
  6. How do I make a cell's contents equal to another cell's contents with macro program?
    By mgmcdevitt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2005, 04:44 PM
  7. Replies: 1
    Last Post: 07-01-2005, 10:57 AM

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