Run Code on Change

TIgerV
TIgerV used Ask the Experts™
on
I have code that updates an electronic Sign every time I push the "SEND" button in Excel.

However, Can I force excel to monitor the cells (only 12 of them) for changes and run the code automatically?

So, If I change cell B3, Excel runs the code I have in the "SEND" button.

Also, I have a cell that is a countdown timer.  Once the timer is started, and as long as the value is greater than "0:00:00", I want to run the code every 10 seconds.

Seems like If I just run the code every 10 seconds, it would do the same thing, I'm not trying to be precise, just a general countdown of values from 10 minutes to 0:00:00
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mechanical Engineer
Most Valuable Expert 2013
Top Expert 2013
Commented:
Yes to both questions.

To watch certain cells for changes, you need a Worksheet_Change sub in the code pane for that worksheet. It might look like:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim targ As Range
Set targ = Union(Range("B2:B4"), Range("D5:D10"))
Set targ = Intersect(targ, Target)
If targ Is Nothing Then Exit Sub

'Call your macro here
End Sub

To run a sub every 10 seconds, you want to use Application.OnTime method. Chip Pearson gives a pretty good description of the process here: http://www.cpearson.com/excel/OnTime.aspx

Author

Commented:
Thank you VERY MUCH!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial