I currently have this code to delete all worksheets in a workbook other than the one named "Data" before running other macros. Currently if "Data" is the only worksheet in the workbook I get an error and the code stops running. This macro is a part of a larger set of macros and I have many workbooks to apply these series of macros on. Is there any way to tweak this code so that even if "Data" is the only sheet I will not get an error?
Thanks for all the help in advance!
VBA Code:
Sub Delete()
Dim xWs As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> "Data" Then
xWs.Delete
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thanks for all the help in advance!