Jake - Thank you for your help.
When I enter a Name that is not in the database and it asks for another search and I type in a good name and it will find it then it will not stop.
I have been unable to insert the
If MyFindNext = vbNo Then
Exit Sub
in the correct place.
If I enter a name that is not in the database several times and then try to quit, it will not quit on the first "No".
Other then that the code works perfect.
Thank you very much.
Option Explicit
Sub LineSearchTEST01(Optional SearchVal As String)
Dim MyValue As String
Dim MyFindNext As Long
Dim sht As Worksheet
Dim Ans As Long
Dim FirstAddress As String
Dim Cel As Range
Dim Counter As Long
If SearchVal = "" Then
MyValue = InputBox("Company Name", "FAX / E-MAIL DATABASE")
Else
MyValue = SearchVal
End If
If MyValue = "" Then
[C3].Select
Exit Sub
End If
For Each sht In Sheets(Array("A", "B", "C", "D", "E", "F", "G", "H", _
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", _
"W", "X", "Y", "Z"))
With sht
sht.Activate
Set Cel = .Columns(3).Find(What:=MyValue)
MyFindNext = vbYes
If Not Cel Is Nothing Then
FirstAddress = Cel.Address
Do
Counter = Counter + 1
Cel.Activate
MyFindNext = MsgBox("Next " & MyValue & "?", vbYesNo, "Find Next")
Set Cel = .Columns(3).FindNext(Cel)
Loop While Not Cel Is Nothing And _
Cel.Address <> FirstAddress And _
MyFindNext = vbYes
End If
End With
If MyFindNext = vbNo Then
Exit Sub
End If
Next
If Counter = 0 Then
Ans = MsgBox("Search could not find '" & MyValue & "'." & _
vbNewLine & " " & vbNewLine & _
"Try another search?", 4, MyValue & " not found")
If Ans = vbYes Then
Call LineSearchTEST01
Else
Sheets("A").Select
[C3].Select
Exit Sub
End If
End If
If MyFindNext = vbYes Then
Call LineSearchTEST01(MyValue)
End If
If MyFindNext = vbNo Then
Exit Sub
End If
End Sub