Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA to delete worksheets | Excel Discussion (Misc queries) | |||
Delete All Worksheets Apart From Some With Particular Name | Excel Discussion (Misc queries) | |||
I can't delete my worksheets | Excel Discussion (Misc queries) | |||
I can't delete my worksheets | Excel Programming | |||
Delete worksheets | Excel Programming |