Macro Adjustment to prevent complete deletion

Bright01
Bright01 used Ask the Experts™
on
EE Pros,

I have a great WS that a number of EE Pros have helped me out with.  It now works incredibly well.  However, I can see a potential problem as I add additional Tabs or integrate this WS into a larger WB with existing Tabs.

The macro for deleting all tabs except the original uses a bit of code that may delete ALL TABs other then the original.  So instead of deleting only the "spawned" tabs (i.e. Priority_Map1, Priority_Map(2), etc. etc., I think it would auto. delete ALL TABS except the Priority_Map Tab.  Can you add a little code that will only delete tabs that have "Priority_Map" with an extension?

Thank you,

B.

Here's the code:

Sub Deletesheet()
Application.EnableEvents = False
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
Application.DisplayAlerts = False
Select Case sht.Name
        Case "Priority_Map"
            'Do Nothing
        Case Else
            sht.Delete
    End Select
Next
Application.DisplayAlerts = True
  Application.EnableEvents = True
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

pls try

Sub Deletesheet()
 Application.EnableEvents = False
 Dim sht As Worksheet
 For Each sht In ActiveWorkbook.Worksheets
 Application.DisplayAlerts = False
 If sht.Name Like "Priority_Map?*" Then
    sht.Delete
 Else
    'Do Nothing
 End If
 Next
 Application.DisplayAlerts = True
   Application.EnableEvents = True
 End Sub

Open in new window

Regards

Author

Commented:
Just what was ordered!  Much thanks,

B.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial