Start a function if cell values changes

  • Thread starter Thread starter daMike
  • Start date Start date
D

daMike

Hello,

I should run a sub or function every time the content
of a cell changes. I use WinXp and Excel 2002.
Hope somebody know how it works!

Thanks in advance!
daMike
 
Hi,

You can use worksheet's Worksheet_Change event.



--
Regards

Haldun Alay

To e-mail me, please remove AT and DOT from my e-mail address.
 
If the cell content is changing due to user input, use a
Worksheet_Change() event macro:

Put this in the worksheet code module (right-click on the worksheet
tab, choose View Code, paste the code in the window that opens,
then click the XL icon on the toolbar to return to XL)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address(0, 0) = "A1" Then MyMacro
End Sub

where "MyMacro" is the name of your macro. Change the cell reference
to suit.

If the cell content is calculated, use the Worksheet_Calculate()
event instead:

Private Sub Worksheet_Calculate()
Static oldA1 As Variant
If Range("A1").Value <> oldA1 Then
MyMacro
oldA1 = Range("A1").Value
End If
End Sub

For more on event macros, see

http://cpearson.com/excel/events.htm
 
Back
Top