ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   active cell to run macro (https://www.excelbanter.com/excel-programming/445327-active-cell-run-macro.html)

kalpesh

active cell to run macro
 
Hello,

it is possibel that when in sheet1 a1 cell is active to run macro

Auric__

active cell to run macro
 
kalpesh wrote:

it is possibel that when in sheet1 a1 cell is active to run macro


One way is the Worksheet_SelectionChange event. Place this in the worksheet's
class:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If "$A$1" = ActiveCell.Address Then
'your code here
End If
End Sub

If you want your code to run when A1 is the only thing selected, change
ActiveCell.Address to Target.Address.

--
I can't believe he would even THINK of something like... like...
Oh, who the hell am I kidding? Yes I can.

Gord Dibben[_2_]

active cell to run macro
 
Auric has pointed you to a method use a selection chamge event.

There are other event types you could use if you choose

BeforeRightClick

BeforeDoubleClick

Sample code..............................

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "B1"
Cancel = True
MyB1Macro
Case "C1"
Cancel = True
MyC15Macro
End Select
End Sub


Gord

On Mon, 06 Feb 2012 11:19:23 -0600, kalpesh
wrote:

Hello,

it is possibel that when in sheet1 a1 cell is active to run macro


Gord Dibben[_2_]

active cell to run macro
 
Please make correction to MyC15Macro

Should read MyC1Macro


Gord

On Mon, 06 Feb 2012 12:11:14 -0800, Gord Dibben
wrote:

Auric has pointed you to a method use a selection chamge event.

There are other event types you could use if you choose

BeforeRightClick

BeforeDoubleClick

Sample code..............................

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Select Case Target.Address(False, False)
Case "A1"
Cancel = True
MyA1Macro
Case "B1"
Cancel = True
MyB1Macro
Case "C1"
Cancel = True
MyC15Macro
End Select
End Sub


Gord

On Mon, 06 Feb 2012 11:19:23 -0600, kalpesh
wrote:

Hello,

it is possibel that when in sheet1 a1 cell is active to run macro



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

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