On Event Delete Worksheet

Mudbutt

Board Regular
Joined
Jul 18, 2011
Messages
158
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, making the file huge. 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 i have this thus far:
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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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