ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Delete All Worksheets Apart From Some With Particular Name (https://www.excelbanter.com/excel-discussion-misc-queries/164152-delete-all-worksheets-apart-some-particular-name.html)

Dave

Delete All Worksheets Apart From Some With Particular Name
 
How would I delete all Worksheets in a Workbook except those called "HOME",
"ONE" and "TWO" (for example).

Thanks!
Dave

JP[_3_]

Delete All Worksheets Apart From Some With Particular Name
 
Sub DeleteSheets()
Dim sht As Worksheet
Application.ScreenUpdating = False

For Each sht In Worksheets
If sht.Name < "HOME" Then
If sht.Name < "ONE" Then
If sht.Name < "TWO" Then
Application.DisplayAlerts = False
sht.Delete
Application.DisplayAlerts = True
End If
End If
End If
Next sht

Application.ScreenUpdating = True
End Sub

---
HTH,
JP

On Oct 30, 7:45 pm, Dave wrote:
How would I delete all Worksheets in a Workbook except those called "HOME",
"ONE" and "TWO" (for example).

Thanks!
Dave





All times are GMT +1. The time now is 11:13 PM.

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