Deleting Sheet with VBA

  • Thread starter Thread starter Bre-x
  • Start date Start date
B

Bre-x

Hi,
I have this code that allows me to delete all sheet but the one i have
selected:

Sub DelSheet()
For Each sheete In Sheets
If ActiveSheet.Index <> sheete.Index Then
Application.DisplayAlerts = False
sheete.Delete
Application.DisplayAlerts = True
End If
Next sheete
End Sub

Is there a way to change this code to allow me to delete all but the
currently selected plus a sheet called "SS"?

Thank you all,

Bre-x
 
One way:

Option Explicit
Sub DelSheet()
Dim sheete As Worksheet
For Each sheete In Worksheets
If sheete.Name = ActiveSheet.Name _
Or LCase(sheete.Name) = "ss" Then
'do nothing
Else
Application.DisplayAlerts = False
sheete.Delete
Application.DisplayAlerts = True
End If
Next sheete
End Sub
 
Back
Top