mschubert

New Member
Joined
Dec 15, 2015
Messages
3
Hiya,

I have created a workbook with multiple worksheets of data. I'm trying to understand macros and formulas but I am not very good!

I want to create a master page which has a search box that will search all of the worksheets for any text that is entered and display the results.

is this something that can be done? If so how?

Thanks.

M :biggrin:
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This is sample code (posted by Jerry Beaucaire) that I've used in the past. In your case, you could modify the MyVal String to reference the cell your search box is located.

Code:
Option Explicit
Public MyVal As String

Sub SuperFIND()
'Author: Jerry Beaucaire
'Date: 8/13/2010
'Summary: Searches all sheets for any text string, activates when found
Dim ws As Worksheet
Dim vFIND As Range

StartOver:
MyVal = Application.InputBox("Enter the contact name to find", "Find In All Sheets", MyVal, Type:=2)
If MyVal = "False" Then Exit Sub
On Error Resume Next

For Each ws In Worksheets
	Set vFIND = ws.Cells.Find(MyVal, LookIn:=xlValues, LookAt:=xlPart)
	If Not vFIND Is Nothing Then
		ws.Activate
		vFIND.Select
		Set vFIND = Nothing
		Exit Sub
	End If
Next ws

MsgBox "Contact not found"
GoTo StartOver

End Sub
3D FIND - Jerry Beaucaire's - Excel Assistant
 
Upvote 0
Hiya,

I have created a workbook with multiple worksheets of data. I'm trying to understand macros and formulas but I am not very good!

I want to create a master page which has a search box that will search all of the worksheets for any text that is entered and display the results.

is this something that can be done? If so how?

Thanks.

M :biggrin:

Hi welcome to the board.

Give this code a try & see if goes in direction you are looking for.

Place code in standard module:

Code:
Sub SearchSheets()
    Dim Sh As Worksheet
    Dim Found As Range
    Dim Search As Variant
    Dim firstaddress As String, msg As String
    
    Do
    Search = InputBox("Enter Search Text", "Search")
    If StrPtr(Search) = 0 Then Exit Sub
    Loop Until Search <> ""
    
     msg = "Search: " & Search & Chr(10) & Chr(10) & "Results:" & Chr(10)
     
    For Each Sh In ThisWorkbook.Worksheets
        With Sh.UsedRange
            Set Found = .Cells.Find(What:=Search, LookIn:=xlValues, lookat:=xlWhole)
            If Not Found Is Nothing Then
                firstaddress = Found.Address
                Do
                    msg = msg & Sh.Name & Space(4) & Found.Address & Chr(10)
                        
                    Set Found = .FindNext(Found)
                Loop While Not Found Is Nothing And Found.Address <> firstaddress
            Else
                msg = msg & Sh.Name & Space(4) & "No Match" & Chr(10)
            End If
        End With
        Set Found = Nothing
    Next
    MsgBox msg, 48, "Search"
End Sub

when run, an inputbox will be displayed where you enter your search text. All worksheets in the workbook will be searched & results reported in a msgbox.

If you are new to macro's suggest that you search for VBA for beginners guides, plenty examples out there and some even free & of course, this board for any assistance needed.

Hope Helpful

Dave
 
Last edited:
Upvote 0
Hi welcome to the board.

Give this code a try & see if goes in direction you are looking for.

Place code in standard module:

Code:
Sub SearchSheets()
    Dim Sh As Worksheet
    Dim Found As Range
    Dim Search As Variant
    Dim firstaddress As String, msg As String
    
    Do
    Search = InputBox("Enter Search Text", "Search")
    If StrPtr(Search) = 0 Then Exit Sub
    Loop Until Search <> ""
    
     msg = "Search: " & Search & Chr(10) & Chr(10) & "Results:" & Chr(10)
     
    For Each Sh In ThisWorkbook.Worksheets
        With Sh.UsedRange
            Set Found = .Cells.Find(What:=Search, LookIn:=xlValues, lookat:=xlWhole)
            If Not Found Is Nothing Then
                firstaddress = Found.Address
                Do
                    msg = msg & Sh.Name & Space(4) & Found.Address & Chr(10)
                        
                    Set Found = .FindNext(Found)
                Loop While Not Found Is Nothing And Found.Address <> firstaddress
            Else
                msg = msg & Sh.Name & Space(4) & "No Match" & Chr(10)
            End If
        End With
        Set Found = Nothing
    Next
    MsgBox msg, 48, "Search"
End Sub

when run, an inputbox will be displayed where you enter your search text. All worksheets in the workbook will be searched & results reported in a msgbox.

If you are new to macro's suggest that you search for VBA for beginners guides, plenty examples out there and some even free & of course, this board for any assistance needed.

Hope Helpful

Dave

Thanks Dave - this is more along the line of what i was looking for will also have a look at those guides.

:)
 
Upvote 0
Thanks Dave - this is more along the line of what i was looking for will also have a look at those guides.

:)

Hi Glad suggestion helpful.

here is a well known site that offers lots of free samples that is always worth visting:http://www.contextures.com/

if you get stuck in your project development, always post your code & explain what it is you are trying to do - plenty on board here to offer help & guidance.

Dave
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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