Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Click in cell to run macro

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Click in cell to run macro

You can use the Worksheet_SelectionChange() event (put this in the
worksheet code module: right-click the worksheet tab and choose View
Code).


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If ActiveCell.Address(False, False) = "A1" Then MyMacro
End Sub

But this will also be run when you tab/arrow into the cell. You might
want to use the double-click event instead:

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
If Target.Address(False, False) = "J10" Then
MyMacro
Cancel = True
End If
End Sub


In article ,
alistew wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Click in cell to run macro

You could use doubleclick event code.

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
'Substitute your cells/macro names.
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "J10"
Cancel = True
MyJ10Macro
Case "AB275"
Cancel = True
MyAB275Macro
End Select
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste the above into that sheet module.


Gord Dibben MS Excel MVP


On Tue, 13 Feb 2007 08:59:02 -0800, alistew
wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Click in cell to run macro

thanks was a great help!

"Gord Dibben" wrote:

You could use doubleclick event code.

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
'Substitute your cells/macro names.
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "J10"
Cancel = True
MyJ10Macro
Case "AB275"
Cancel = True
MyAB275Macro
End Select
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste the above into that sheet module.


Gord Dibben MS Excel MVP


On Tue, 13 Feb 2007 08:59:02 -0800, alistew
wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Click in cell to run macro

thanks so much this was a great help

"JE McGimpsey" wrote:

You can use the Worksheet_SelectionChange() event (put this in the
worksheet code module: right-click the worksheet tab and choose View
Code).


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If ActiveCell.Address(False, False) = "A1" Then MyMacro
End Sub

But this will also be run when you tab/arrow into the cell. You might
want to use the double-click event instead:

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
If Target.Address(False, False) = "J10" Then
MyMacro
Cancel = True
End If
End Sub


In article ,
alistew wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default Click in cell to run macro


hi

im back again!

is it possible to use this code on merged cells? i am unsure how merged
cells are recognised. if i merge a1:d1, if you select it the name box will
display it as a1 but this is not recognised in the code. if i enter a1:d1 in
the code this is not recognised. any ideas????

"Gord Dibben" wrote:

You could use doubleclick event code.

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
'Substitute your cells/macro names.
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "J10"
Cancel = True
MyJ10Macro
Case "AB275"
Cancel = True
MyAB275Macro
End Select
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste the above into that sheet module.


Gord Dibben MS Excel MVP


On Tue, 13 Feb 2007 08:59:02 -0800, alistew
wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Click in cell to run macro

Well, aside from the fact that you shouldn't be using merged cells
(they're the spawn of the devil, and cause innumerable problems with
formatting, sorting, copying and pasting, etc), this may work for you:

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
MsgBox Target.Address
'Substitute your cells/macro names.
With Target
If Not Intersect(Range("A1"), .Cells) Is Nothing Then
Cancel = True
MyA1Macro
ElseIf Not Intersect(Range("J10"), .Cells) Is Nothing Then
Cancel = True
MyJ10Macro
ElseIf Not Intersect(Range("AB275"), .Cells) Is Nothing Then
Cancel = True
MyAB275Macro
End If
End With
End Sub




In article ,
alistew wrote:

is it possible to use this code on merged cells? i am unsure how merged
cells are recognised. if i merge a1:d1, if you select it the name box will
display it as a1 but this is not recognised in the code. if i enter a1:d1 in
the code this is not recognised. any ideas????

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Click in cell to run macro

I don't have an answer for the "merged cells" problem other than to
say........don't use that feature which causes no end of problems.

If A1:D1 are merged to accommodate a title, use Center Across Selection instead.


Gord

On Tue, 20 Feb 2007 07:25:15 -0800, alistew
wrote:


hi

im back again!

is it possible to use this code on merged cells? i am unsure how merged
cells are recognised. if i merge a1:d1, if you select it the name box will
display it as a1 but this is not recognised in the code. if i enter a1:d1 in
the code this is not recognised. any ideas????

"Gord Dibben" wrote:

You could use doubleclick event code.

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
'Substitute your cells/macro names.
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "J10"
Cancel = True
MyJ10Macro
Case "AB275"
Cancel = True
MyAB275Macro
End Select
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste the above into that sheet module.


Gord Dibben MS Excel MVP


On Tue, 13 Feb 2007 08:59:02 -0800, alistew
wrote:

Is it possible to click in a cell in Excel to run a macro? assign macro to
cell type thing.




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
Macro: automatically initiating upon cell click pmp613 Excel Discussion (Misc queries) 1 December 28th 06 09:46 AM
Can I add a Macro to right-click Menu? Ed Excel Discussion (Misc queries) 8 October 11th 06 02:43 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
Click on cell-calendar drops down-click on date-date fills cell. . George Setting up and Configuration of Excel 1 April 15th 05 08:22 AM
Can I launch macro by a cell click ? Cedric Dennis Excel Discussion (Misc queries) 2 March 11th 05 04:34 PM


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

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

About Us

"It's about Microsoft Excel"