Hello Forum!
I would like to delete all except one sheets in the workbook by pressing onto a button. So I wrote the folllowing code (its obviously only a part)
Application.DisplayAlerts = False
For Each Worksheet In Worksheets
If (Worksheet.Name <> "Instructions") Then
Worksheet.Delete
End If
Next
Application.DisplayAlerts = True
and put it into a Module in the same workbook. The button itself is in one of the sheets to be deleted, so I assign a simple macro to it which is just calling the code above.
Well, sounds simple, but it does not work, with "Subscript out of range" error at the attempt to delete one (not the first one) of the sheets.
Searching around suggested that the problem appears when the worksheet I try to access does not exist (missspelling of a name or so). but in my code I dont really use it.
I am out of ideas! Any help is highly appreciated!
Thanks in advance!
Igor.
I would like to delete all except one sheets in the workbook by pressing onto a button. So I wrote the folllowing code (its obviously only a part)
Application.DisplayAlerts = False
For Each Worksheet In Worksheets
If (Worksheet.Name <> "Instructions") Then
Worksheet.Delete
End If
Next
Application.DisplayAlerts = True
and put it into a Module in the same workbook. The button itself is in one of the sheets to be deleted, so I assign a simple macro to it which is just calling the code above.
Well, sounds simple, but it does not work, with "Subscript out of range" error at the attempt to delete one (not the first one) of the sheets.
Searching around suggested that the problem appears when the worksheet I try to access does not exist (missspelling of a name or so). but in my code I dont really use it.
I am out of ideas! Any help is highly appreciated!
Thanks in advance!
Igor.