Start a function if cell values changes

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
 
H

Haldun Alay

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.
 
J

J.E. McGimpsey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top