How To Search For A Word Within A Workbook

aedctalk

Board Regular
Joined
Oct 9, 2010
Messages
156
Hi,

Wondering if i had a serach term in L3 like "uniforms"

are there any macros out there.. or any way possible to search all sheets of a workbook and then have it take me to the row and sheet that each instance occurs?

or if easier. something that would find those words and then copy all rows that have that word or phrase into a empty sheet called search results?


Just curious if there is anything like that out there? Or if its even a possiblity with excel/vba?

Thanks so much!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can do this manually quickly...right click any sheet tab, left click on Select All Sheets, hit Ctrl+F, enter your search word, and click Find Next. That would find teh word(s). The macro would be needed to do a copy and paste, so post back if you need that, such as if this is a recurring task, or if just selecting Select All Sheets does it for you. PS, remember to ungroup the sheets when you are done.
 
Upvote 0
Try this in the code window of the worksheet with L3:
Make sure you're not using the first two columns for anything, otherwise change range("A1") to where you'd like the output to go.

Sub SearchForWord()

Dim ws As Worksheet
Dim c As Range
Dim i As Integer
Dim strSearch As String

strSearch = Range("L3")
i = 1
With Range("A1")
For Each ws In ThisWorkbook.Worksheets
For Each c In ws.UsedRange
If c = strSearch Then
.Cells(i, 1) = c.Parent.Name
.Cells(i, 2) = c.Address
i = i + 1
End If
Next c
Next ws
End With

End Sub
 
Last edited:
Upvote 0
Thank you for your help you guys!


I tried the code however on this part



If c = strSearch Then

I get runtime error 13 "type Mismatch"


Thanks so much for code! What exactly will it do? :)
 
Upvote 0
Try c.value instead of c to make it explicit, perhaps that's your error 13 problem. It seems not to care with my version of Excel.

The Find method would be quicker but involve more code, depends how big the used ranges are in your worksheets.

Let me know your Excel version if it still doesn't work.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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