Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
Created July 12, 2014 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwagnerco/bdb62ea31f45033fc004 to your computer and use it in GitHub Desktop.
Save danwagnerco/bdb62ea31f45033fc004 to your computer and use it in GitHub Desktop.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUT : SheetName, the name (string) of the sheet we're looking for
'OUTPUT : True or false (sheet was found, sheet was not found)
'SPECIAL CASE : none
'EXAMPLES BELOW:
'
'assume that a sheet named "YaGotMe" exists
'DoesSheetExist("YaGotMe")
'>> True
'
'assume that a sheet named "NotHere" does NOT exist
'DoesSheetEixst("NotHere")
'>> False
'
Public Function DoesSheetExist(SheetName As String) As Boolean
Dim Obj As Object
On Error Resume Next
Set Obj = ThisWorkbook.Worksheets(SheetName)
If Err = 0 Then
DoesSheetExist = True
Else
DoesSheetExist = False
End If
On Error GoTo 0
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment