How to code an event to call a macro?

  • Thread starter Thread starter kris
  • Start date Start date
K

kris

How can I program an event, such as a double click on a
particular cell in a worksheet to excute VBA code.
Different cells in that worksheet would trigger different
VBA functions.
Thanks
 
Watch for linewrap.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range,
Cancel As Boolean)
Select Case Target
Case Range("A2")
Call This
Case Range("B2")
Call That
Case Else
' Do whatever
End Select
End Sub

Sub This()
Range("A2").Font.ColorIndex = 3
End Sub

Sub That()
Range("B2").Font.ColorIndex = 5
End Sub


Tested using Excel 97SR2 on Windows 98SE,

HTH
Paul
 
Hi,
One way would be to create from the Froms Menu a button
the right click on that button and assign the macro to
that button.
Another way is to create a Control button from the
Control Toolbox Menu then right click on the control
button. Select view code, copy over the code and assign
to the click property.
Good Luck
 
Back
Top