Lampoa
Lampoa

Reputation: 149

Excel VBA DoubleClick

I'm working on a work project where I have an excel sheet with values that turn red when they are out of spec. What I'd like to do is be able to double click on a cell and have the sheet in my workbook pop up that has trending data on it. I have already created the sheet with the graph on it. Long story short, I'd like to be able to double click on a specific cell and have it bring up the corresponding sheet.

I have tried this code, and it will not work. Is anyone able to maybe write code from scratch or alter the code so I could use it? The cell I'm trying to click on is N9, and the sheet I want it to open is called "Alpha Final Rinse"

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
    Sheets("Alpha Final Rinse").Select
End Sub

I'm doing this in Excel 2013. Thank you!

Upvotes: 3

Views: 31293

Answers (2)

user4039065
user4039065

Reputation:

If you only want N9 to be able to switch focus to another worksheet, isolate Target with the Intersect method.

In the data worksheet's code sheet:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
    If Not Intersect(Target, Range("N9")) Is Nothing Then
        cancel = True
        Worksheets("Alpha Final Rinse").Activate
    End If
End Sub

Note that cancel = True is necessary to stop the user entering in-cell edit mode (assuming that has been enabled in Options).

Upvotes: 3

Gary's Student
Gary's Student

Reputation: 96753

Your code will work if:

  • it is installed in the worksheet code area of your data sheet (the sheet whose cells you are double-clicking)
  • macros are enabled
  • the file type is .xlsm rather than .xlsx

Upvotes: 0

Related Questions