ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OnChange Event for a Cell (https://www.excelbanter.com/excel-programming/286880-onchange-event-cell.html)

Michael Kintner

OnChange Event for a Cell
 
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



Ron de Bruin

OnChange Event for a Cell
 
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



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Michael Kintner" wrote in message ...
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





Tom Ogilvy

OnChange Event for a Cell
 
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

--
Regards,
Tom Ogilvy

"Michael Kintner" wrote in message
...
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





Chip Pearson

OnChange Event for a Cell
 
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


"Michael Kintner" wrote in message
...
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






All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com