How to code an event to call a macro?

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
 
P

pfsardella

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
 
K

Kathy

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
 

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