Find text

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
426
Office Version
  1. 2019
Platform
  1. Windows
Hi All

I have a workbook which contains 12 sheets, is it possible write a macro which will search for a text string which could be on any of the 12 sheets

Thanks a lot

colin
 
Thanks for getting back... I have some issues that I'm hoping this will solve.

As I posted in another topic, I have 1 workbook that contains a sheet on which I have some account numbers in column E (preceeded by zeros so the VALUE() func will have to be used). I'm wanting to go through those account numbers and try to find matches in a 2nd workbook (which has multiple sheets, 1 for each month) in column E also. When it finds a match I was hoping to highlight the row, or maybe note the row number it was found on so that I may go back and track them down.

I'm currently doing this process by hand and it's insane. lol

any assistance would be great!
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I've tried using the macro the way you have it above for testing reasons, just using the input box to manually add an account number to check for and it always comes back as unable to find the text.

I've opened a workbook and done a copy/paste directly into the input box from the sheet and it's still saying unable to find a match. What could be wrong?
 
Upvote 0
Yet another Mod to this code recuested

This is the code from Page three
Instead of displaying the results how could it be modified to copy the results of the search and paste to a separate sheet.

or

Copy the search word to the next column beside the row where the words was found

Public Sub FindText()
'Run from standard module, like: Module1.

Dim ws As Worksheet, Found As Range, rngNm As String
Dim myText As String, FirstAddress As String, thisLoc As String
Dim AddressStr As String, foundNum As Integer

myText = InputBox("Enter text to find")

If myText = "" Then Exit Sub

For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, MatchCase:=False)

If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
foundNum = foundNum + 1
rngNm = .Name
AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf
thisLoc = rngNm & " " & Found.Address

Sheets(rngNm).Select
Range(Found.Address(RowAbsolute:=False, _
ColumnAbsolute:=False)).Select

myFind = MsgBox("Found one """ & myText & """ here!" & vbCr & vbCr & _
thisLoc, vbInformation + vbOKCancel + vbDefaultButton1, "Your Result!")

If myFind = 2 Then Exit Sub

Set Found = .UsedRange.FindNext(Found)

Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With

Next ws

If Len(AddressStr) Then
MsgBox "Found: """ & myText & """ " & foundNum & " times." & vbCr & _
AddressStr, vbOKOnly, myText & " found in these cells"
Else:
MsgBox "Unable to find " & myText & " in this workbook.", vbExclamation
End If

End Sub
 
Upvote 0
search only in 1 column or 1 row

Hi I am using this great search code in several workbooks.

However, I am now trying to get it to work in a workbook to find dates. The workbook can have dates anywhere in the workbook but I only want it to look ia specific column column in each sheet since the date could be in several places at the same time.

I only want it to find the date in column D and then go to that cell in that column.

Is this possible? and how? thank you very much for any assistance.

John
 
Upvote 0
Change this:

If Not Found Is Nothing Then
FirstAddress = Found.Address


To:

If (Not Found Is Nothing And Found.Column = 4)Then
FirstAddress = Found.Address
 
Upvote 0
Run time error 91

thank you for the quick reply.

I tried using it and it seemed to work ok found where the date was in that column only. but then it had an error.

Run time error 91

Object variable or with block variable not set


Nothing else was changed.

thank you again for your help.

John
 
Upvote 0
I feel almost guilty asking this as everyone seems to be jumping on the bandwagon!!

However, having moved the guilt to one side.....

I am using the code above and it works fine with one exception - the text search has to be an exact match.

Is it possible to carry out a partial text search? eg Looking for Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch but only using "gogoch" in search field.

Thanks in anticipation.

Graham
 
Upvote 0

Forum statistics

Threads
1,216,753
Messages
6,132,514
Members
449,732
Latest member
Viva

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