Delect all Worksheets that begind with Sheet

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi There,

This is a strange request for some code.


I need some code that is Triggered "On Open" of the workbook, that deletes all the worksheets of that workbook that begin with Sheet.

I.e. if I have 3 Sheets And I name one MASTER, and the other 2 are called Sheet1 and Sheet2, they must be deleted when the workbook is opened again.

the number of sheets that will be deleted will change every day.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this in the ThisWorkbook module

Code:
Private Sub Workbook_Open()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Me.Worksheets
    If ws.Name Like "Sheet*" Then ws.Delete
Next ws
Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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