PDA

View Full Version : repeated action



lior03
04-01-2008, 04:50 AM
hello
i weant to search a string across a sheet.if my choice is not found i want to get a chance to search again.i also want another chance if i'm right.
how do i get it.

On Error GoTo ERR_HANDLER
Dim x As String
Dim tryagain As Boolean
tryagain = True
Cells.Select
Do While tryagain = True
x = InputBox("choose value to search...", "searching....")
If Len(x) = 0 Then Exit Sub
selection.Find(What:=x, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
If MsgBox(ActiveCell.Address, vbExclamation + vbYesNo, x & " - is at: ") = vbYes Then
tryagain = True
End If
Exit Sub
ERR_HANDLER: If MsgBox("String not found !", vbCritical + vbYesNo, "another try?") = vbYes Then
tryagain = True
End If
Loop


thanks

Bob Phillips
04-01-2008, 05:35 AM
On Error GoTo ERR_HANDLER
Dim x As String
Cells.Select
Do
x = InputBox("choose value to search...", "searching....")
If Len(x) = 0 Then Exit Sub
Selection.Find(What:=x, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
If MsgBox(ActiveCell.Address & vbNewLine & "Try again?", _
vbInformation + vbYesNo, x & " found at -") = vbYes Then
GoTo loop_continue
Else
Exit Do
End If
ERR_HANDLER:
If MsgBox("Not found - try again?", vbYesNo, "another try?") = vbNo Then Exit Do
Resume loop_continue
loop_continue:
Loop