Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default call macro if cell is selected

Is it possible to have a macro run by clicking on a range or a single cell?

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default call macro if cell is selected


Hello Corey,

Yes you can. The drawback is the macro must be placed in the event code
of each Worksheet where you want to use it.

Here is the code. MyRange can be a single cell or range. Change MyMacro
to the name of the macro you wish to execute.


Code:
--------------------

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = $A2:$E100
If Not Application.Intersect(Target, MyRange) Is Nothing Then Call MyMacro
End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=561911

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default call macro if cell is selected

Corey,
Check out the SelectionChange event.
You get new selected range in the Target argument.

NickHK

"Corey" wrote in message
...
Is it possible to have a macro run by clicking on a range or a single

cell?

Corey....




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default call macro if cell is selected

Not necessarily, as there is the Workbook_SelectionChange.
And if you use Application level events, a single routine for the whole of
excel.
http://www.cpearson.com/excel/AppEvent.htm

NickHK

"Leith Ross" wrote
in message ...

Hello Corey,

Yes you can. The drawback is the macro must be placed in the event code
of each Worksheet where you want to use it.

Here is the code. MyRange can be a single cell or range. Change MyMacro
to the name of the macro you wish to execute.


Code:
--------------------

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = $A2:$E100
If Not Application.Intersect(Target, MyRange) Is Nothing Then Call

MyMacro
End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=561911



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default call macro if cell is selected

Thanks guys,
As the sheet i placed the code in was part of a copy and paste new sheet
code, the code transfers to the other sheets also.
I am using it to bring up a msg box to warn that a formula is contained in
that cell selected. (Similar to protecting the cells)
It works great.

Regards

Corey




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default call macro if cell is selected

data validate - info is another way doing that



"Corey" skrev:

Thanks guys,
As the sheet i placed the code in was part of a copy and paste new sheet
code, the code transfers to the other sheets also.
I am using it to bring up a msg box to warn that a formula is contained in
that cell selected. (Similar to protecting the cells)
It works great.

Regards

Corey



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
call macro X by cell value cyote101[_2_] Excel Programming 4 July 7th 06 09:14 PM
How do i call a macro from a cell KhanhNguyen Excel Programming 1 June 24th 06 11:45 AM
Macro to take selected cells times a selected cell Craig Excel Programming 4 October 24th 05 12:54 AM
Call an Excel Macro when a Sheet is selected [email protected] Excel Programming 0 October 16th 03 07:01 PM
Call a macro or sub based on the name of a cell? Tom Ogilvy Excel Programming 1 August 26th 03 06:15 PM


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

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"