Deleting Sheet with VBA

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
 
D

Dave Peterson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top