Searching worksheet for a string and returning list of all matching values

caststone

New Member
Joined
Feb 3, 2015
Messages
17
I have a worksheet with many lines of data and I want to be able to find a way to type a string in and be presented with a list of all lines in the worksheet that contain the string, no matter what column they are in. So for example -

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]boy[/TD]
[TD]dog[/TD]
[TD]hat[/TD]
[TD]blue bird[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ball[/TD]
[TD]horse[/TD]
[TD]birdman[/TD]
[TD]car[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]lorry[/TD]
[TD]keys[/TD]
[TD]hand[/TD]
[TD]cup[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]bird[/TD]
[TD]dog[/TD]
[TD]boy[/TD]
[TD]ball[/TD]
[/TR]
</tbody>[/TABLE]

I would like to type the word "bird" and be presented with the following list -



[TABLE="width: 500"]
<tbody>[TR]
[TD]1[/TD]
[TD]boy[/TD]
[TD]dog[/TD]
[TD]hat[/TD]
[TD]blue bird[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ball[/TD]
[TD]horse[/TD]
[TD]birdman[/TD]
[TD]car[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]bird[/TD]
[TD]dog[/TD]
[TD]boy[/TD]
[TD]ball[/TD]
[/TR]
</tbody>[/TABLE]


I am not sure where to start. Is this best tackled with VBA? is there something I could do with pivot tables? I want to make it as simple as possible to enter the search term so user does not have to enter wildcards to get the full results.

Any clues would be gratefully received :nya:
 
Thank you very much for that, this is working to output to a results sheet but I have a few questions -
How do I overwrite previous results every time I run the query?
Is the search case sensitive?
Can I search for multiple strings? For example 'bird' and 'dog' in same line?
Thank you for all your help so far
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Several answers were supplied. Which post provided the answer you used and now want modified?

Do you want it case sensitive?

And how many values would you be looking for 2 or 3 or 10 or 20?
 
Upvote 0
Try this:
Will copy rows to a sheet named Results

Code:
Sub Find_Me()
'Modified  9/12/2018  12:22:01 PM  EDT
Application.ScreenUpdating = False
Dim r As Range
Dim lastrow As Long
lastrow = 1
Dim ans As String
ans = InputBox("Search for what value")
    For Each r In ActiveSheet.UsedRange
        If InStr(r.Value, ans) Then Rows(r.Row).Copy Sheets("Results").Rows(lastrow): lastrow = lastrow + 1
    Next
Application.ScreenUpdating = True
End Sub

Sorry, I thought I was replying to an individual post.

This is the code I used and I would like it NOT to be case sensitive and to enter 2 or search terms maximum.
 
Upvote 0
Sorry, I thought I was replying to an individual post.

This is the code I used and I would like it NOT to be case sensitive and to enter 2 or search terms maximum.
Looking for more then one value is easy for me. But then one row is created every time a value is found on the same row and that is not what you want. So someone else here at Mr. Excel may have a answer for you.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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