by Allen Wyatt
(last updated June 25, 2018)
If you have Excel 97 and you create a macro that runs whenever a change occurs in your worksheet, you may have noticed an interesting phenomenon--the macro doesn't always run when you think it should. It runs just fine if you enter a new formula in a cell or enter a new value, but it doesn't run if you use data validation and someone picks something from the validation drop-down list.
Microsoft knows about this problem. In fact, you can find more information about it in the Knowledge Base, here:
There are essentially several ways you can work around the problem. First, you could upgrade to a newer version of Excel. I'm not exactly sure which version it was corrected in, but I do know that in Excel 2003 selecting something from a data validation drop-down does trigger the Worksheet_Change event.
The second option is to use some other method of changing the worksheet data than with data validation. For instance, you could use a combo box from the Controls toolbox. Setting one up is a bit more difficult than using data validation, but much more versatile.
Finally, you could create a formula reference to the validated cell, and then trigger your macro from the Worksheet_Calculate event. For instance, if your validated cell is A7, then you could use the formula =A7 in a different cell. When the value in A7 changes (the user selects from the drop-down list), then a recalculation is begun because the results of the formula change. This, of course, triggers the Worksheet_Calculate event, where you could implement your macro. (Since the Worksheet_Calculate event can be triggered by lots of changes, you would need to add some checking code to your handler to make sure that the validation change is what ultimately triggered the event.)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2398) applies to Microsoft Excel 97.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
When developing a macro that others may use, you might want to test it out to make sure it works properly if an ...Discover More
Make your macros too long, and Excel may just refuse to run them at all. This tip explains what the limit is for macros, ...Discover More
Macros that run automatically when you open or close a workbook are quite helpful. You may not want them to run, however, ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.