OnChange Event for a Cell

  • Thread starter Thread starter Michael Kintner
  • Start date Start date
M

Michael Kintner

Where do I find the OnChange Event for a cell.

For example Cell A1. I change the value in the cell I would like to perform
something. How do I create it or find it?

Thank you for your help in advance!!! (smile)

Mike
 
Read this
http://www.cpearson.com/excel/events.htm

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("a1"), Target) Is Nothing Then
MsgBox "you changed A1"
End If
End Sub

Place the code in the Sheet module

Right click on a sheet tab and choose view code
Paste the code there
Alt-Q to go back to Excel
 
Right click on the sheet tab and select view code.

In the left dropdown, select Worksheet and in the right dropdown select
Change (dropdowns at top of code module).

This puts in a declaration for the change event which is fired whenever a
cell is edited or is updated with a DDE link (xl2000 and beyond).

In the event, you can use an if statement to see if it was a change to A1
that triggered the event. Target holds a reference to the cell/cells that
triggered the event

Private Sub Worksheet_Change(ByVal Target As Range)
if Target.Address = "$A$1" then

code to perform something

End if
End Sub
 
Michael,

Use the Change event procedure. In the code module for the
appropriate worksheet, use code like the following:


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.EnableEvents = False
' do something here
Application.EnableEvents = True
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top