Martin_H
Board Regular
- Joined
- Aug 26, 2020
- Messages
- 190
- Office Version
- 365
- Platform
- Windows
Hi,
I would like to adjust my macro (see the code at the bottom) so it will delete every worksheet higher than sheet(16). Sheet(16) can not be deleted.
Currently I am using this line, which I do not like.
Also I am not sure if I should use "On Error Resume Next" or not.
Thank you guys.
I would like to adjust my macro (see the code at the bottom) so it will delete every worksheet higher than sheet(16). Sheet(16) can not be deleted.
Currently I am using this line, which I do not like.
VBA Code:
With ThisWorkbook
.Sheets(17).DELETE: .Sheets(18).DELETE: .Sheets(19).DELETE: .Sheets(20).DELETE: .Sheets(21).DELETE: .Sheets(22).DELETE
End With
Also I am not sure if I should use "On Error Resume Next" or not.
Thank you guys.
VBA Code:
Sub deleteSheetIfExists()
On Error Resume Next
With Application
.DisplayAlerts = False
With ThisWorkbook
.Sheets(17).DELETE: .Sheets(18).DELETE: .Sheets(19).DELETE: .Sheets(20).DELETE: .Sheets(21).DELETE: .Sheets(22).DELETE
End With
.DisplayAlerts = True
End With
On Error GoTo 0
End Sub