+ Reply to Thread
Results 1 to 14 of 14

Run macro everytime cell content changes

  1. #1
    Registered User
    Join Date
    01-13-2008
    Posts
    19

    Run macro everytime cell content changes

    I want a macro to run everytime the value in say cell D6 changes.

    Anyone know how to do this?

    Many Thanks

  2. #2
    Registered User
    Join Date
    02-13-2006
    Posts
    46
    goto macro window by pressing alt+F11
    Select the sheet from left panel. there will be two drop down. from the left drop down select worksheet and from right drop down list select the event change.

    to access rows and cols you can use following

    Please Login or Register  to view this content.
    hope it helps..

    Ashish
    Last edited by VBA Noob; 01-15-2008 at 02:31 PM.

  3. #3
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    Thanks, i have now tried using this:

    Please Login or Register  to view this content.
    The problem now is that the macro does not fire when the value in cell D5 is changed. The macro run on its own works fine.

    Any ideas?

    Thanks!

  4. #4
    Registered User
    Join Date
    01-07-2008
    Posts
    38

    Move the macro

    Hi,

    You need to make sure the macro (which is an "event handler") is located in the code module for the worksheet it applies to.

    Right click the worksheet (e.g., Sheet1) in the Project explorer and select "View Code". Copy the macro to the page that brings up. Then it should work any time the value in cell D5 is changed.

    Chuck L

  5. #5
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    Hi,

    Tried that, no luck.

    Here is the macro that I want to run:

    Please Login or Register  to view this content.
    Thanks

  6. #6
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    I have just realised that the problem is because the cell D5 where i want changed values to be detected is a validation list where values are changed via a drop down list.

    I tested suing another cell where this was not the case.

    Does anyone therefore know how to run a macro when the value in a cell that uses a validation list is changed?

    Many Thanks

  7. #7
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    The intersect method will work with one limitation , if the user drops the list and selects the same value that was already selected from the list the macro will run the same as if he had selected a different value.

    In this example I named the cell.

    Please Login or Register  to view this content.
    If it is neccessary to avoid running the macro when a selection is made but the value doesn't change , you might need to set a variable equal to the value of the cell, and use a nested IF statement.
    Last edited by SuitedAces; 01-15-2008 at 06:51 PM.

  8. #8
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    Thanks,

    That works fine when i use msgbox "Test" everytime a selection is made from the list. However, it will not work when I want to initiate a macro when an item in the dropdown is changed.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516
    You must be using xl97...
    worksheet_change event doesn't detect the change made via validation dropdown in '97
    enter any unused cell =D5
    and use worksheet_calculate event instead.

  10. #10
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    No im definatly using excel 2003.

    Im very new to vba so would you be able to guide me further as to how to use Worksheet_calculate? Do i simply just copy the code I had in Worksheet_change?

    Thanks

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516
    Then the code should work as it is.
    1) Most probably EnableEvents property was accidentally set to False.
    Or Security setting
    2) Have you enabled Macro when open ?

    Run following code once and try again
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    If the message box works then you should be able to replace the msgbox line with a call to your sub.
    Is your procedure a public sub located in a standard module ?

    Please Login or Register  to view this content.
    Last edited by SuitedAces; 01-16-2008 at 11:04 PM.

  13. #13
    Registered User
    Join Date
    01-13-2008
    Posts
    19
    Sub is public and in a standard module.

    Thanks

  14. #14
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Well if that is the case then you should post your workbook , because your subroutine should run.

    The msgbox has demonstrated that it the event code is firing , now that you replaced the Msgbox line with a call to your sub it won't just decide to ignore the call .
    Do you get an error message ?
    Last edited by SuitedAces; 01-17-2008 at 01:36 PM.

+ 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