ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Help deleting worksheets (https://www.excelbanter.com/excel-discussion-misc-queries/22533-help-deleting-worksheets.html)

Wilhelmutt

Help deleting worksheets
 
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.



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
"Wilhelmutt" wrote in message
...
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.





Wilhelmutt

That works just fine! Thank you.


All times are GMT +1. The time now is 05:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com