Joe thanks for your help, I was wondering if you could glance over my code for a second. The results work fine when i find one result, eveything come up fine.
The output comes out fine. It will say The Document (offset to -1 cell) will refer to (offset to -2).
I am currently having a problem whereby it says 14 results are found and it displays only say 10 on the pop up message dialog. The last message it leaves say there The document and leaves the rest as blank. It also leaves the part where i have "refer to" in some of the results it finds in the msgbox.
Another problem is when i drag the dialog box, it drags all the way around the screen as like there is a problem with memory.
Would there be a mistake as having a loop in the wrong place.
Cheers!
Sub Search()
'Standard Module code, like: Module1!
Dim f%, foundNum%
Dim ws As Worksheet
Dim Found As Range
Dim myText$, FirstAddress$, thisLoc$, rngNm$, AddressStr$
myText = ActiveSheet.Range("B7").Value
If myText = "" Then Exit Sub
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
'Option: Search Sub-Folders as well?
.SearchSubFolders = False 'Option: True or False!
'Option Current Folder or a defined folder?
'.LookIn = CurDir
'Or
.LookIn = "S:\Document\Database"
'Option: Only Search this type of file?
.Filename = "Database.xls"
.Execute
For f = 1 To .FoundFiles.Count
Set Wb = Workbooks.Open(Filename:=.FoundFiles(f), ReadOnly:=True)
For Each ws In Wb.Worksheets
With ws
Set Found = .UsedRange.Find(what:=myText, LookAt:=xlWhole, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
CodeStr = Found.Offset(0, -1).Value & " refers to " & Found.Offset(0, -2).Value
If Len(CodeStr) = 0 Then CodeStr = "blank."
Do
foundNum = foundNum + 1
rngNm = .Name
AddressStr = AddressStr & .Name & " " & " Document Title is " & CodeStr & vbCrLf
thisLoc = rngNm & " " & Found.Address
ActiveSheet.Select
Sheets(rngNm).Select
Range(Found.Address(RowAbsolute:=False, _
ColumnAbsolute:=False)).Select
If myFind = 1 Then Exit Sub
Set Found = .UsedRange.FindNext(Found)
CodeStr = Found.Offset(0, -1).Value & Found.Offset(0, -2).Value
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With
Next ws
If Len(AddressStr) Then
MsgBox "Found: """ & myText & """ " & foundNum & " time(s)." & vbCr & _
AddressStr, vbOKOnly, myText & " has been found"
Else:
MsgBox "Unable to find " & myText & " in Workbook: " & Wb.Name, vbExclamation
End If
ActiveWorkbook.Close
Next f
End With
Application.ScreenUpdating = True
End Sub