Sub searchname()
Dim DestBook As Workbook, SrcBook As Workbook
Dim Lost1 As Variant
Dim Lost2 As Variant
Dim Lost3 As Variant
Dim rngFound1 As Range, sh As Worksheet, shOutput As Worksheet
Dim rngFound2 As Range
Dim rngFound3 As Range
Dim combo1 As String
Dim combo2 As String
Application.ScreenUpdating = False
Set SrcBook = ThisWorkbook
search_criteria.Show
Lost1 = SrcBook.Worksheets("Sheet4").Cells(1, 3).Value
Lost2 = SrcBook.Worksheets("Sheet4").Cells(2, 3).Value
Lost3 = SrcBook.Worksheets("Sheet4").Cells(3, 3).Value
combo1 = SrcBook.Worksheets("Sheet4").Cells(4, 3).Value
combo2 = SrcBook.Worksheets("Sheet4").Cells(5, 3).Value
SrcBook.Worksheets("Sheet4").Range("C1:C5").ClearContents
'Lost = InputBox(prompt:="Type in the details you are looking for!", _
' Title:=" Find what?", Default:="")
If Lost1 = "" Then Exit Sub
Set DestBook = Workbooks.Open("C:\Documents and Settings\jgr\Desktop\WORKING\Database.xls")
Set shOutput = SrcBook.Worksheets("Find_Result")
shOutput.Range("A2:A65536").ClearContents
For Each sh In DestBook.Worksheets
With sh.UsedRange
Set rngFound1 = .Find(What:=Lost1, LookIn:=xlValues)
Set rngFound2 = .Find(What:=Lost2, LookIn:=xlValues)
Set rngFound3 = .Find(What:=Lost3, LookIn:=xlValues)
If combo1 = "AND" & combo2 = "AND" Then
If Not rngFound1 Is Nothing Then
If Not rngFound2 Is Nothing Then
If Not rngFound3 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
End If
End If
If combo1 = "OR" & combo2 = "OR" Then
If Not rngFound1 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
ElseIf Not rngFound2 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound2.Parent.Name & "'" & "!" & rngFound2.Address, _
ScreenTip:="Match found in cell: " & rngFound2.Address(0, 0), _
TextToDisplay:=sh.Name
ElseIf Not rngFound3 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound3.Parent.Name & "'" & "!" & rngFound3.Address, _
ScreenTip:="Match found in cell: " & rngFound3.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
If combo1 = "AND" & combo2 = "OR" Then
If Not rngFound1 Is Nothing Then
If Not rngFound2 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
End If
ElseIf Not rngFound3 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound3.Parent.Name & "'" & "!" & rngFound3.Address, _
ScreenTip:="Match found in cell: " & rngFound3.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
If combo2 = "AND" & combo1 = "OR" Then
If Not rngFound1 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
ElseIf Not rngFound2 Is Nothing Then
If Not rngFound3 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound2.Parent.Name & "'" & "!" & rngFound2.Address, _
ScreenTip:="Match found in cell: " & rngFound2.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
End If
If combo1 = "" Then
If Not rngFound1 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
If combo1 = "AND" & combo2 = "" Then
If Not rngFound1 Is Nothing Then
If Not rngFound2 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
End If
If combo1 = "OR" & combo2 = "" Then
If Not rngFound1 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound1.Parent.Name & "'" & "!" & rngFound1.Address, _
ScreenTip:="Match found in cell: " & rngFound1.Address(0, 0), _
TextToDisplay:=sh.Name
ElseIf Not rngFound2 Is Nothing Then
shOutput.Hyperlinks.Add _
Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
Address:=DestBook.FullName, _
SubAddress:="'" & rngFound2.Parent.Name & "'" & "!" & rngFound2.Address, _
ScreenTip:="Match found in cell: " & rngFound2.Address(0, 0), _
TextToDisplay:=sh.Name
End If
End If
End With
Next
shOutput.Activate
shOutput.Range("A1").Select
DestBook.Close Savechanges:=True
On Error GoTo 0
Set DestBook = Nothing
Set SrcBook = Nothing
End Sub