ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Click event on cell triggers a macro (https://www.excelbanter.com/excel-programming/282389-click-event-cell-triggers-macro.html)

Kris

Click event on cell triggers a macro
 
How can I program an event, such as a double click on a
particular cell in a worksheet, to excute VBA code. Click
events on different cells in that worksheet would trigger
different VBA functions.
Thanks for any help.


mudraker[_13_]

Click event on cell triggers a macro
 

you would need to do something like this.

The code needs to be placed in the worksheet module


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range,
Cancel As Boolean)
Dim SelCell

' identify which cell has been double clicked
SelCell = Target.Column & ", " & Target.Row

Select Case SelCell
Case "2, 3"
place code here

End Select


End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/


Chip Pearson

Click event on cell triggers a macro
 
Kris,

Use the BeforeDoubleClick event in the code module for the appropriate
sheet. Put the following code in the Sheet's code module:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Select Case Target.Address(False, False)
Case "A1"
' code for A1
Cancel = True
Case "B2"
' code for B2
Cancel = True
Case "C3"
' code for C3
Cancel = True
Case Else
End Select
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"kris" wrote in message
...
How can I program an event, such as a double click on a
particular cell in a worksheet, to excute VBA code. Click
events on different cells in that worksheet would trigger
different VBA functions.
Thanks for any help.





All times are GMT +1. The time now is 01:56 PM.

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