Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro when cell contents change

How can I get a macro to run automatically only when a
specific cell e.g. A1 has its value changed?
Many thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Run macro when cell contents change

In VBA module in "ThisWorkbook" capture the
SelectionChange event. If the address of the target is
the correct cell address, then execute code.

Example :

Sub Worksheet_SelectionChange (ByVal Target as Range)
If Target.Address = "$A$1" then
' put your code here
end if
End Sub
-----Original Message-----
How can I get a macro to run automatically only when a
specific cell e.g. A1 has its value changed?
Many thanks.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Run macro when cell contents change

Tim,

Worksheet event code

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On errot GoTo ws_exit
If Not Intersect(Target, Range("A1")) Is Nothing Then
'your code here
End If

ws_exit:
Application.EnableEvents = True
End Sub


Right-click on the sheet tab name, select the View Code option, and put the
code in there.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks

"Tim Smith" wrote in message
...
How can I get a macro to run automatically only when a
specific cell e.g. A1 has its value changed?
Many thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Run macro when cell contents change

Philip,

If you use Worksheet_SelectionChange event then it goes in the appropriate
worksheet code module not ThisWorkbook. For ThisWorkbook, you would use

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

and test the sheet as well.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"philip" wrote in message
...
In VBA module in "ThisWorkbook" capture the
SelectionChange event. If the address of the target is
the correct cell address, then execute code.

Example :

Sub Worksheet_SelectionChange (ByVal Target as Range)
If Target.Address = "$A$1" then
' put your code here
end if
End Sub
-----Original Message-----
How can I get a macro to run automatically only when a
specific cell e.g. A1 has its value changed?
Many thanks.
.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Macro change column contents James C[_2_] Excel Discussion (Misc queries) 4 January 25th 10 02:36 PM
change cell contents when pull down menu choices change jb21 Excel Worksheet Functions 3 November 21st 08 10:34 PM
Launch macro when drop-down contents change... Tom Mackay Excel Discussion (Misc queries) 1 September 6th 07 08:52 PM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM
run code after cell contents change Brian Excel Programming 0 September 5th 03 08:37 PM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"