Hi Team,
I am checking sheetname "Main" in Thisworkbook.
if sheetName not found... Macro to throw error MsgBox "Sheet doesn't exist"
But macro is giving SubScript out of Range for below code in Function. on error resume not working
ShtExists = (LCase(wbk.Sheets(ShtName).Name) = LCase(ShtName))
Thanks
mg
I am checking sheetname "Main" in Thisworkbook.
if sheetName not found... Macro to throw error MsgBox "Sheet doesn't exist"
But macro is giving SubScript out of Range for below code in Function. on error resume not working
ShtExists = (LCase(wbk.Sheets(ShtName).Name) = LCase(ShtName))
VBA Code:
Option Explicit
Sub testSheedName()
Dim wbk As Workbook
Set wbk = ThisWorkbook
If Not ShtExists("Main", wbk) Then
MsgBox "Sheet doesn't exist"
Exit Sub
End If
End Sub
Public Function ShtExists(ShtName As String, Optional wbk As Workbook) As Boolean
If wbk Is Nothing Then Set wbk = ActiveWorkbook
On Error Resume Next
ShtExists = (LCase(wbk.Sheets(ShtName).Name) = LCase(ShtName))
On Error GoTo 0
End Function
Thanks
mg