Assign Macro to a Cell

B

Bob Myers

Is there a way to assign a macro to a cell such that clicking (or double
clicking) the cell executes the macro?
Thanks,
RUM
 
P

Paul C

You can pick up either a selction change

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row=1 and Target.Column=1 then
'do Stuff
End If
End Sub

a double click
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, _
ByVal Target As Range, ByVal Cancel As Boolean)
If Target.Row=1 and Target.Column=1 then
'do Stuff
End If
End Sub

or a right click
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, ByVal Cancel As Boolean)
If Target.Row=1 and Target.Column=1 then
'do Stuff
End If
End Sub

The code would go in VBA on the sheet where your target cell resides and not
a seperate module. Change the Target.Row=1 and Target.Column=1 to whatever
cell you desire.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top