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

How do I execute a specific macro when I click on a cell? For example, if I
click in cell B3, I want to run a macro. Suggestions?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Exceute macro when cell is clicked

Use the Worksheet_SelectionChange method.\

This would go on the individual sheet in the VBA Editor

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address < "$B$3" Then Exit Sub
Do Stuff
End Sub

--
If this helps, please remember to click yes.


"Kent McPherson" wrote:

How do I execute a specific macro when I click on a cell? For example, if I
click in cell B3, I want to run a macro. Suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Exceute macro when cell is clicked

One limitation of Paul's approach is that the macro would get also get called
if the cell were entered via the ARROW keys or the TAB key or even the enter
key.

Another approach is to Insert a hyperlink in B3 to a Place in the Document
(namely B3). At first blush, this seems a little silly (why insert a
hyperlink that goes nowhere?). We now can trap the click with a hyperlink
follow event macro:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Address = "$B$3" Then
Call hello
End If
End Sub

Now the cell will perform just like a button. You can even add a mouse-over
popup message if you want.
--
Gary''s Student - gsnu2007M


"Kent McPherson" wrote:

How do I execute a specific macro when I click on a cell? For example, if I
click in cell B3, I want to run a macro. Suggestions?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Exceute macro when cell is clicked

Yes, this is great. Thanks.

"Paul C" wrote in message
...
Use the Worksheet_SelectionChange method.\

This would go on the individual sheet in the VBA Editor

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address < "$B$3" Then Exit Sub
Do Stuff
End Sub

--
If this helps, please remember to click yes.


"Kent McPherson" wrote:

How do I execute a specific macro when I click on a cell? For example,
if I
click in cell B3, I want to run a macro. Suggestions?





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Exceute macro when cell is clicked

That is a good point. This is a more robust method.
--
If this helps, please remember to click yes.


"Gary''s Student" wrote:

One limitation of Paul's approach is that the macro would get also get called
if the cell were entered via the ARROW keys or the TAB key or even the enter
key.

Another approach is to Insert a hyperlink in B3 to a Place in the Document
(namely B3). At first blush, this seems a little silly (why insert a
hyperlink that goes nowhere?). We now can trap the click with a hyperlink
follow event macro:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Address = "$B$3" Then
Call hello
End If
End Sub

Now the cell will perform just like a button. You can even add a mouse-over
popup message if you want.
--
Gary''s Student - gsnu2007M


"Kent McPherson" wrote:

How do I execute a specific macro when I click on a cell? For example, if I
click in cell B3, I want to run a macro. Suggestions?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Exceute macro when cell is clicked

Very cool. I love this newsgroup!

"Gary''s Student" wrote in message
...
One limitation of Paul's approach is that the macro would get also get
called
if the cell were entered via the ARROW keys or the TAB key or even the
enter
key.

Another approach is to Insert a hyperlink in B3 to a Place in the Document
(namely B3). At first blush, this seems a little silly (why insert a
hyperlink that goes nowhere?). We now can trap the click with a hyperlink
follow event macro:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Parent.Address = "$B$3" Then
Call hello
End If
End Sub

Now the cell will perform just like a button. You can even add a
mouse-over
popup message if you want.
--
Gary''s Student - gsnu2007M


"Kent McPherson" wrote:

How do I execute a specific macro when I click on a cell? For example,
if I
click in cell B3, I want to run a macro. Suggestions?





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
autoshape with macro changes colour when clicked Haresh Excel Programming 5 July 31st 07 02:51 PM
Change cell value when right-clicked/double-clicked grime[_5_] Excel Programming 5 October 17th 05 01:52 PM
To exceute a Macro when worksheet is deactivted and data is changed Hari[_3_] Excel Programming 0 August 3rd 04 07:28 PM
How to end macro on inital active worksheet containing macro button that was clicked Silverhawk1 Excel Programming 2 May 14th 04 03:58 PM
Macro to increase cell value by 1 each time button clicked fozzer[_2_] Excel Programming 2 April 29th 04 01:58 PM


All times are GMT +1. The time now is 04:45 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"