I am trying to create a macro that will delete all worksheets except for worksheets I do not want deleted. I want all worksheets to be deleted except for worksheets ABC and DEF. I am having trouble and would be greatful for any help. Thank you.
The code I am using is as follows:
Sub DeleteSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "ABC" Then
Application.DisplayAlerts = False
If ws.Name <> "DEF" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next ws
End Sub
Bookmarks