Finding worksheet based on user input

jrudolph

New Member
Joined
Apr 25, 2008
Messages
35
I have a workbook with a bunch of individual worksheets, that will continue to grow overtime. Each spreadsheet is a statement for billing for individuals and their may be similar names.

I have a "Search" button on the main worksheet page. I want to be able to enter text into cell "B3" and then click search and be taken to the page closest to what I type in. The workbook is sorted alphabetically so if I am taken to the first closest match I can search from there.

For example maybe I have two Smith, J worksheets (the second of which may be listed as Smith, J (2)). I want to be able to type in, "Sm", "Smi", "Smith" or "Smith, J" and be taken to the first "Smith" worksheet in the workbook.

Further if no matches come up, I would like there to be an message box that says that.

So far I have the following basics. I am not really sure where to go from here.

Code:
Sub Search_Sheets()
 
    Dim SearchName As String
 
    SearchName = ActiveSheet.Range("B3").Value
 
    If SearchName <> "" Then
    Sheets(SearchName).Select
 
    Else
    MsgBox "Terminate", vbOKOnly, "Error"
    End If
 
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You could record a .Find macro and utilize that, though it would be looking for cell values (Billing name/Invoice Number and the like), not sheet names.


There's another option to utilize a Combobox (activex)
This is for a ComboBox on Sheet1
Code:
Private Sub Worksheet_Activate()
'Every Time you activate Sheet1, the Combo Box re-loads
'Goes in Sheet1
        EnableEvents = False
        ComboBox1.Clear
        For shtIdx = 2 To Sheets.Count
            ActiveSheet.ComboBox1.AddItem Sheets(shtIdx).Name
        Next
        EnableEvents = True
End Sub
Private Sub ComboBox1_Click()
'Goes in Sheet1
'Activates the selected sheet
    Sheets(ComboBox1.Text).Activate
End Sub
 
Upvote 0
Thats not what I was looking for... but that is a pretty sweet deal. Simple and does better than what I was actually looking for!

Thanks!
 
Upvote 0
What if I want to include all sheets in the drop down, except one? How would that look?

The sheet I want to exclude is Sheet2 (BillingTemplate)

If its an easy tweak that would be great, otherwise its not a big deal. Thanks again!
 
Upvote 0
This is more along the lines of your orig. rqst.

Code:
Private Sub CommandButton1_Click()
   Dim SearchName As String
 
    SearchName = ActiveSheet.Range("B3").Value
    SheetFound = False
    
    For ShtIdx = 1 To Sheets.Count
        If Sheets(ShtIdx).Name Like "*" & SearchName & "*" Then
            SheetFound = True
            Sheets(ShtIdx).Activate
            Exit For
        End If
    Next
    If Not SheetFound Then MsgBox "Terminate", vbOKOnly, "Error"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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