View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Marco to Delete Worksheets

Hi,

ALT+F11 to open VB editor, right click 'ThisWorkbook' and insert module and
paste the code below in and run it

Sub selete_Sheets()
Dim ws As Worksheet
Dim DelFlag As Boolean
Dim MyArray As Variant
MyArray = Array("Template", "TY", "LY", "52WkEnd", "Macro")
For Each ws In ThisWorkbook.Worksheets
DelFlag = True
For x = LBound(MyArray) To UBound(MyArray)
If ws.Name = MyArray(x) Then
DelFlag = False
Exit For
End If
Next
If DelFlag Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
End Sub

Mike

"CM4@FL" wrote:

I want to create a macro the deletes all worksheets within my workbook except
5. The worksheets I don't want deleted are named: Template, TY, LY, 52WkEnd,
and Macro. What code should I used to achieve this?