![]() |
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 |
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 |
All times are GMT +1. The time now is 06:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com