Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Macro from workSheet by Double Clicking in a cell

Tags:

excel

vba

I want to call a Macro (Rpt1) in Module1 by double-clicking a cell in Sheet2. I'm not certain how to do this. I seem to have the double click event executing from Sheet2 but I don't know how to call the macro I have in Module1.

like image 647
MWebb Avatar asked Dec 20 '25 03:12

MWebb


1 Answers

You need to paste this code into your SHEET code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const clickADDRESS As String = "A1" '<--- or whatever cell you want it to be

    If Not Intersect(Target, Me.Range(clickADDRESS)) Is Nothing Then
        Call Rpt1
    End If

End Sub

which will call the macro in module code (my example)

Sub Rpt1()

   MsgBox "This worked"

End Sub

By sheet code here's an illustration: enter image description here

like image 113
pgSystemTester Avatar answered Dec 21 '25 22:12

pgSystemTester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!