I am attempting to delete a sheet from a workbook using this code:
Sub deleteSheet(oldSheet)
' Deletes the work space sheet
Sheets(oldSheet).Select
ActiveWindow.SelectedSheets.Delete
End If
End Sub
This works great if the sheet exists but if it is not there it deletes the active sheet that I do not want to delete. Any suggestions on how to use the On Error logic to skip the delete and allow the code to continue?
I have tried this but it did not work properly.
Sub deleteSheet(oldSheet)
On Error Resume Next
' Deletes the work space sheet
Sheets(oldSheet).Select
ActiveWindow.SelectedSheets.Delete
End If
End Sub
Sub deleteSheet(oldSheet)
' Deletes the work space sheet
Sheets(oldSheet).Select
ActiveWindow.SelectedSheets.Delete
End If
End Sub
This works great if the sheet exists but if it is not there it deletes the active sheet that I do not want to delete. Any suggestions on how to use the On Error logic to skip the delete and allow the code to continue?
I have tried this but it did not work properly.
Sub deleteSheet(oldSheet)
On Error Resume Next
' Deletes the work space sheet
Sheets(oldSheet).Select
ActiveWindow.SelectedSheets.Delete
End If
End Sub