Maurice
Maurice

Reputation: 57

Start macro by double click

I'm trying to start a macro through double clicking a cell.

I copied this code directly from the internet, but it is not working when I double click the cell C40.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("C40")) Is Nothing Then
        Cancel = True
        SelectPayFreq.Show
    End If
End Sub

Upvotes: 3

Views: 29593

Answers (2)

mielk
mielk

Reputation: 3940

The code for worksheet events must be placed in the module for a proper worksheet not in a regular module.

enter image description here

Upvotes: 5

Gary's Student
Gary's Student

Reputation: 96753

Make sure the code is in the worksheet code area:

Because it is worksheet code, it is very easy to install and automatic to use:

  1. right-click the tab name near the bottom of the Excel window
  2. select View Code - this brings up a VBE window
  3. paste the stuff in and close the VBE window
  4. make sure Macros are enabled and Events are enabled

Upvotes: 4

Related Questions