There is indeed. How about this?
Use this function:-
Function DoesSheetExist(sSheetName As String) As Boolean
Dim sht As Object
For Each sht In ThisWorkbook.Sheets
If sht.Name = sSheetName Then DoesSheetExist = True: Exit Function
Next
End Function
An example of how to use this:-
Sub TestOfSheetExists()
Dim sSheetToDelete As String
Dim sht As Object
sSheetToDelete = InputBox("Enter sheet name", "Sheet to delete")
If sSheetToDelete = "" Then Exit Sub
If DoesSheetExist(sSheetToDelete) = True Then
Application.DisplayAlerts = False
Sheets(sSheetToDelete).Delete
Application.DisplayAlerts = True
Else
MsgBox "The specified sheet name doesn't exist.", vbInformation, "Error!"
End If
End Sub
HTH,
Dax
That is perfect..exactly what I was looking for. Thank you so much for the information.
Chris