Find Sheet

gerald24

Board Regular
Joined
Apr 28, 2017
Messages
95
Hi Guys,

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:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I tried in an new workbook. so there's a sheet1, sheet2, sheet3. Supposedly, when I try to search sheet, it should bring me to sheet 1 right? but it only returns the "That sheet name does not exist!" because it returns false.
 
Upvote 0
Except you are typing the Sheet name as it actually appears "Sheet 1" and "Sheet1" are different
 
Upvote 0
Except you are typing the Sheet name as it actually appears "Sheet 1" and "Sheet1" are different

but what I want to accomplish is to search a part of the sheet name and it will lead me to the sheets that contains it.

Example, I want to search for "Apples" sheet, but I only searched for "App" but it will still lead me to that sheet or any other sheets that contains "App"
 
Upvote 0

Forum statistics

Threads
1,223,767
Messages
6,174,388
Members
452,561
Latest member
amir5104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top