MWebb
MWebb

Reputation: 33

Calling a Macro from workSheet by Double Clicking in a cell

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.

Upvotes: 3

Views: 623

Answers (1)

pgSystemTester
pgSystemTester

Reputation: 9932

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

Upvotes: 4

Related Questions