PC Review


Reply
Thread Tools Rate Thread

Delete All Worksheets, Except for Three

 
 
=?Utf-8?B?cnlndXk3Mjcy?=
Guest
Posts: n/a
 
      16th Mar 2007
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!

--
RyGuy
 
Reply With Quote
 
 
 
 
=?Utf-8?B?cnlndXk3Mjcy?=
Guest
Posts: n/a
 
      16th Mar 2007
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!!

--
RyGuy


"ryguy7272" wrote:

> 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!
>
> --
> RyGuy

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete row 1 in all worksheets Jodie Microsoft Excel Programming 7 29th Dec 2009 06:13 PM
Delete Worksheets Sal Microsoft Excel Programming 4 7th May 2009 01:41 AM
Delete All Worksheets Apart From Some With Particular Name =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Misc 1 31st Oct 2007 01:30 AM
I can't delete my worksheets =?Utf-8?B?Y2h1Y2ttY2M=?= Microsoft Excel Programming 7 17th Mar 2006 10:11 PM
Delete worksheets andym Microsoft Excel Programming 6 24th Nov 2003 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 PM.