Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete All Worksheets, Except for Three

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 dont
have €śZZZ€ť in the tab. I tried €śZZZ*€ť but didnt 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Delete All Worksheets, Except for Three

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 dont
have €śZZZ€ť in the tab. I tried €śZZZ*€ť but didnt 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to delete worksheets Mark_F via OfficeKB.com Excel Discussion (Misc queries) 2 August 27th 09 06:04 PM
Delete All Worksheets Apart From Some With Particular Name Dave Excel Discussion (Misc queries) 1 October 31st 07 01:30 AM
I can't delete my worksheets Dillon Excel Discussion (Misc queries) 1 March 5th 07 06:10 PM
I can't delete my worksheets chuckmcc Excel Programming 7 March 17th 06 10:11 PM
Delete worksheets andym Excel Programming 6 November 24th 03 04:15 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"