On Event Coding

Mudbutt

Board Regular
Joined
Jul 18, 2011
Messages
158
I have a dashboard worksheet, and I'm trying to figure out how to unhide and activate another worksheet within the workbook upon double clicking cell "C4".

Does anyone know how to do this? My Worksheet_Change and Target.Address code doesn't seem to be doing it.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try using this event instead:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'your code here
End Sub

I assume you already have the code to unhide and activate, just put that in the eventhandler shown above
 
Upvote 0
Wouldn't the Worksheet_BeforeDoubleClick event be the one to use?
 
Upvote 0
Try like this

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address(False, False) = "C4" Then
    Cancel = True
    With Sheets("Sheet1")
        .Visible = xlSheetVisible
        .Select
    End With
End If
End Sub
 
Upvote 0
Thank you so much VoG, that worked perfectly. One question, what is the function of the "Cancel = True" portion?
 
Upvote 0
By default double clicking a cell puts it into Edit mode. Setting Cancel to True exits Edit mode.
 
Upvote 0
Hey, VoG:

I have a follow up question for you. I have a dashboard page with a bunch of totals on it and I'm creating this event code so that it gives specific detail of that item when it is double clicked. I didn't want to do this via pivot tables because the pivots display too much unnecessary data when drilling down so i basically made a page that links to all my pivots and I'm improvising.

However, to save space on this workbook, I think it would be most practical if everytime someone double-clicked it creates the sheet as new, and then fills in the data for the first time with formulas so that i don't have tons of worksheets just hidden with prebuilt formulas. With this logic, I was thinking that I would need some kind of delete sheet event code so that each time it's only creating one sheet and the other that was created before be deleted.

Would i do this with select case, and name the sheets that i don't want deleted in this file, and have it delete all the rest? The sheet names i need intact are "MasterList" & "Dashboard". I'm not really sure how to write this code, but thus far, this is what i have:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address(False, False) = "C4" Then
    Cancel = True
    Application.ScreenUpdating = False
    Sheets.Add.Name = "SunOp-FGSch"
    Sheets("SunOp-FGSch").Activate
    Sheets("SunOp-FGSch").Range("A1").FormulaR1C1 = "Materials"
    Sheets("SunOp-FGSch").Range("B1").FormulaR1C1 = "Description"
    Sheets("SunOp-FGSch").Range("C1").FormulaR1C1 = "FG Scheduled"
    Sheets("SunOp-FGSch").Range("A1:C1").Select
        With Selection.Font
            .ThemeColor = xlThemeColorDark1
            .Bold = True
            .Name = "Arial"
            .Size = 10
        End With
        With Selection.Interior
            .ThemeColor = xlThemeColorLight1
        End With
    Sheets("SunOp-FGSch").Range("A2:A5000").Formula = "=IF(AND(MasterList!E3=""Sun Optics"", MasterList!T3>0),MasterList!B3,"""")"
    Sheets("SunOp-FGSch").Range("A2:A" & lastRow).Sort _
        Key1:=Sheets("SunOp-FGSch").Columns("A"), Order:=xlDescending
    Application.ScreenUpdating = True
End If
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top