Delete All Worksheets, Except for Three

G

Guest

I found some VBA code (on this Discussion Group that was posted a while back)
which allows a user to delete all worksheets except for three. I am
wondering if there is a way to get Excel to delete all worksheets which don’t
have “ZZZ†in the tab. I tried “ZZZ*†but didn’t have any success with that.
Basically, I am wondering if the * (wildcard) symbol is not recognized in
VBA…

My code is below:

Sub DelteAllWS()
Dim mySht As Worksheet
Application.DisplayAlerts = False
For Each mySht In ActiveWorkbook.Worksheets
If mySht.Name <> "ZZZ - USA Firms" And mySht.Name <> "ZZZ - RQ 2000-2006"
And mySht.Name <> "ZZZ - 2006 Pulse Global 600" Then
mySht.Delete
End If
Next mySht
Application.DisplayAlerts = True
End Sub

Would like to use:
If mySht.Name <> "ZZZ*" Then
mySht.Delete
...............................................
Thanks!
 
G

Guest

Well, I just figured it out...
Sub DelAllWorksheets()
Application.DisplayAlerts = False
Dim Sh As Worksheet
For Each Sh In ActiveWorkbook.Worksheets
If InStr(1, Sh.Name, "Z") Then
Sh.Select False
Else
Sh.Delete
End If
Next Sh
Application.DisplayAlerts = True
End Sub

My hope is that this may help others...
Happy Excelling!!
 

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