Help deleting worksheets

W

Wilhelmutt

I have a spreadsheet that has a huge number of worksheets that need to be
deleted. I want to use a wildcard in the criteria as the sheet naming
convention is admin_user and there are 70 users. Hence I want to delete any
sheet that starts admin_. I have tried a wildcard in an "if" statement but it
does not work. Any help would be greatly appreciated.
 
R

Robin Hammond

Try this. Back up your workbook first. You can't undo the deletions.

Sub RemoveAdminSheets()
Dim shTest As Worksheet

If MsgBox("Have you backed up this workbook?", vbYesNo) = vbNo Then Exit Sub
Application.DisplayAlerts = False

For Each shTest In Worksheets

If shTest.Name Like "admin_*" Then shTest.Delete

Next shTest
Application.DisplayAlerts = True
End Sub

Robin Hammond
www.enhanceddatasystems.com
 
Top