I have a macro which deletes selected worksheets from a workbook. The macro has been working fine for many users for 3 or 4 years. I installed it on a user's PC today that created a problem. Here is the code:
The problem is that when I step through the macro, the program exits (ends, stops) at the first Sheets(i).Delete line. Since this has never happened before. I assume it must be an Excel setting. Any ideas?
Code:
Dim i As Integer
Dim ws As Worksheet
On Error Resume Next
Sheets("Sheet1").Range("AA:BB").Delete
Do
For i = 3 To Worksheets.Count
If Sheets(i).Name Like "Step*" Then
If i > 3 Then
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
End If
ElseIf Sheets(i).Name Like "By Tool*" Or Sheets(i).Name Like "*TWO*" Then
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
ElseIf Not Sheets(i).Name Like "*Shipset*" And Not Sheets(i).Name Like "*Number*" Then
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
End If
Next i
Loop Until Worksheets.Count = 5
The problem is that when I step through the macro, the program exits (ends, stops) at the first Sheets(i).Delete line. Since this has never happened before. I assume it must be an Excel setting. Any ideas?
Last edited by a moderator: