This is the kind of problem that drives me crazy. The following works. It deletes all sheets that have the name sheet.
The following should delete all sheets EXCEPT the ones named "OriginalData" and "SalesPeople".
The above proc deletes "OriginalData" and
"SalesPeople".
I'm sure that it's simple, but....
Code:
Sub DeleteWorksheets()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sheet As Worksheet
For Each sheet In ActiveWorkbook.Worksheets
If InStr(1, LCase(sheet.Name), "sheet") Then
sheet.Delete
End If
Next sheet
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Code:
Sub CleanCommissionsBySalesBreakDown()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sheet As Worksheet
'On Error Resume Next
For Each sheet In ActiveWorkbook.Worksheets
If Not InStr(1, LCase(sheet.Name), "OriginalData") Or
Not InStr(1, LCase(sheet.Name), "SalesPeople") Then
sheet.Delete
End If
Next sheet
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
"SalesPeople".
I'm sure that it's simple, but....