if worksheet exists vba code example
Example: excel vba test if worksheet exists
Function WorksheetExists(pShtName As String, Optional pWb As Workbook) As Boolean
Dim sht As Worksheet
If pWb Is Nothing Then Set pWb = ThisWorkbook
On Error Resume Next
Set sht = pWb.Sheets(pShtName)
On Error GoTo 0
WorksheetExists = Not sht Is Nothing
End Function