ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro when updating a cell (https://www.excelbanter.com/excel-programming/337919-run-macro-when-updating-cell.html)

Jim Hartley

Run a macro when updating a cell
 
I want to run a Macro when the contents of a cell are changed. I am familiar
with running a macro when updating a worksheet or when clicking a button but
can not find the right event for running one when only a cell has changed.

Richard Buttrey

Run a macro when updating a cell
 
On Mon, 22 Aug 2005 05:17:03 -0700, "Jim Hartley" <Jim
wrote:

I want to run a Macro when the contents of a cell are changed. I am familiar
with running a macro when updating a worksheet or when clicking a button but
can not find the right event for running one when only a cell has changed.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("MyCell")) Is Nothing Then
'....Your code
End If


End Sub


(Thanks to Bob Phillips for pointing me in this direction a few months
ago).

Rgds

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________

Bob Phillips[_6_]

Run a macro when updating a cell
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
'do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jim Hartley" <Jim wrote in message
...
I want to run a Macro when the contents of a cell are changed. I am

familiar
with running a macro when updating a worksheet or when clicking a button

but
can not find the right event for running one when only a cell has changed.





All times are GMT +1. The time now is 08:23 PM.

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