Announcement

Collapse
No announcement yet.

Run Macro By Double-Clicking Cell

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run Macro By Double-Clicking Cell



    Is there a way to enable a macro by double-clicking a cell?

    Currently, I'm running an AutoFilter macro that automatically references a second sheet when the specific cell is selected. The problem is that when a user does a search for an item (Ctrl+F), the macro will immediately initiate and refer to the other cell which confuses the user.

    Ideally, I want the macro to be initiated ONLY when the user DOUBLE-CLICKS on the cell.

    Here's the code that I'm using:

    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column = 1 And Target.Row <= Cells(Rows.Count, 1).End(xlUp).Row Then
            Application.EnableEvents = False
            On Error Resume Next
            Worksheets("Worksheet").howAllData
            Worksheets("Worksheet").Range("A1:A4231").AutoFilter Field:=2, Criteria1:=Target
            Worksheets("Worksheet").Activate
            Application.EnableEvents = True
        End If
    End Sub
    Thanks in advance.
    Last edited by Dave Hawley; December 27th, 2006, 09:54.

  • #2
    Re: Enable An Macro By Double-clicking A Cell

    Use the Worksheet_BeforeDoubleClick Event.

    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'your code
    End Sub
    Cancel=True means the double click for the Target doesn't go into Edit mode.
    Last edited by Dave Hawley; December 27th, 2006, 09:57.

    Comment


    • #3


      Re: Run Macro By Double-Clicking Cell

      Thank you! Works perfectly.

      Comment

      Working...
      X