![]() |
Assign Macro to a Cell
Is there a way to assign a macro to a cell such that clicking (or double
clicking) the cell executes the macro? Thanks, RUM |
Assign Macro to a Cell
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. -- If this helps, please remember to click yes. "Bob Myers" wrote: Is there a way to assign a macro to a cell such that clicking (or double clicking) the cell executes the macro? Thanks, RUM . |
Assign Macro to a Cell
You would probably learn a heck of a lot if you read this:
http://www.cpearson.com/excel/Events.aspx -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. "Paul C" wrote: 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. -- If this helps, please remember to click yes. "Bob Myers" wrote: Is there a way to assign a macro to a cell such that clicking (or double clicking) the cell executes the macro? Thanks, RUM . |
All times are GMT +1. The time now is 09:56 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com