View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Deleting all worksheets in a workbook except two

Sub TryNow()
Dim mySht As Worksheet
Application.DisplayAlerts = False
For Each mySht In ActiveWorkbook.Worksheets
If mySht.Name < "Buttons" And mySht.Name < "Data" Then
mySht.Delete
End If
Next mySht
Application.DisplayAlerts = True
End Sub

HTH,
Bernie
MS Excel MVP


"lewscannon" wrote in message
...
I would like to write a macro that deletes all worksheets in a workbook
except for two, called "Buttons" & "Data". The problem is that the amount

of
and names of the worksheets won't be static, so I can't simply write
"Worksheets ("Sheet1").Delete". I thank you in advance for your help.