Hi Guys,
Could you please check what's missing? I want to find sheet even though part of its name only is being searched.
Thaaaaaaanks
Could you please check what's missing? I want to find sheet even though part of its name only is being searched.
Code:
Sub FindWS()
Dim strWSName As String
strWSName = InputBox("Enter the sheet name to serach for")
If strWSName = vbNullString Then
Exit Sub
End If
If SheetExists(strWSName) Then
Worksheets(strWSName).Activate
Else
'look if it at least contains part of the name
Dim s As Worksheet
For Each s In ThisWorkbook.Sheets
If InStr(s.Name, strWSName) > 0 Then
s.Activate
Exit Sub
End If
Next s
MsgBox "That sheet name does not exist!"
End If
End Sub
Code:
Function SheetExists(strWSName As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(strWSName)
If Not ws Is Nothing Then SheetExists = True
End Function
Thaaaaaaanks
Last edited: