Microsoft Excel Question:
Download Questions PDF

How do I run a macro every time a certain cell changes its value?

Answer:

There is an event called Worksheet_Change which is triggered when a value is entered (it will not fire when a formula result changes). One of the arguments to this event is 'Target' which is a reference to what changed. Since this event will occur whenever a value changes - you can use the target to see if it is the cell you are interested in:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C5")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring has changed!
'Do whatever you need to do...
End If
End Sub

Download MS Excel Interview Questions And Answers PDF

Previous QuestionNext Question
I want to add a toolbar to my spreadsheet that when clicked, brings up Userform1?When a button is drawn onto a sheet the assign macro is not displayed. When right-clicking on the button the "Assign Macro" context menu item is not present?