Hi Guy/Gals
ive been trying to run a code to delete Specific Sheets From a workbook but unfortunailty it wasn't as easy i first thought.
i need it to delete a sheet called Workspace or Workspace NW and both if both are present
my code keep returning back an error if only workpspace if present but still deletes it
the code willl delete both if there
and the error is at
Worksheets("Workspace NW").delete
at the bottom
i know ive kind of over done the coding on this but i havent been doing this very long and sure there proably a much simplier format to do it but sadly am not that good yet.
ive been trying to run a code to delete Specific Sheets From a workbook but unfortunailty it wasn't as easy i first thought.
i need it to delete a sheet called Workspace or Workspace NW and both if both are present
my code keep returning back an error if only workpspace if present but still deletes it
the code willl delete both if there
and the error is at
Worksheets("Workspace NW").delete
at the bottom
VBA Code:
Application.DisplayAlerts = False 'Search tabs for Refence and delete else find other refrence
Dim check As Boolean
For Each Sheet In Worksheets
If Sheet.Name Like "Workspace" Then check = True: Exit For
Next
If check = True Then
Worksheets("Workspace").delete
Else
For Each Sheet In Worksheets
If Sheet.Name Like "Workspace NW" Then check = True: Exit For
Next
If check = True Then
Worksheets("Workspace NW").delete
Else
Application.DisplayAlerts = True
Exit Sub
End If
End If
Application.DisplayAlerts = False ' search for refrence and delete
For Each Sheet In Worksheets
If Sheet.Name Like "Workspace" Then check = True: Exit For
Next
If check = True Then
Worksheets("Workspace NW").delete
Else
Sheets("Homepage").Select
Application.DisplayAlerts = True
Exit Sub
End If
i know ive kind of over done the coding on this but i havent been doing this very long and sure there proably a much simplier format to do it but sadly am not that good yet.