Return Value from MsgBox

G

Guest

If the string from the input box is not found, I want to rerun the code if
the retry button is selected from the message box.

How do I fix the code below to make this work?

Sub FindStr_sub()
Dim s As String, t As String, q As String
Dim r As Range
Dim response As Byte
t = Chr(10) & Chr(10)
s = Application.InputBox("Enter the Word: ", "Locate 'Word'")
DoOver:
For Each r In ActiveSheet.UsedRange
With r
If InStr(1, .Value, s) > 0 Then
q = q + .Address & " " & .Value & t
End If
End With
Next
If q <> "" Then
MsgBox "Found the Word in Cell(s)" & t & q, , "Word Location"
Else
MsgBox "Did not find the Word " & t & Chr(34) & s & Chr(34),
vbRetryCancel, "Word Location"
If response = vbRetry Then
GoTo DoOver
Else
End If
End If
End Sub
 
M

Mike Fogleman

Dim response as Variable, then make it = to the msgbox:

Sub FindStr_sub()
Dim s As String, t As String, q As String
Dim r As Range
Dim response 'As Byte
t = Chr(10) & Chr(10)
s = Application.InputBox("Enter the Word: ", "Locate 'Word'")
DoOver:
For Each r In ActiveSheet.UsedRange
With r
If InStr(1, .Value, s) > 0 Then
q = q + .Address & " " & .Value & t
End If
End With
Next
If q <> "" Then
MsgBox "Found the Word in Cell(s)" & t & q, , "Word Location"
Else
response = MsgBox("Did not find the Word " & t & Chr(34) & s & Chr(34), _
vbRetryCancel, "Word Location")
If response = vbRetry Then
GoTo DoOver
Else
End If
End If
End Sub

Mike F
 
G

Guest

Thanks Mike,

That and relocating the DoOver label has it working now.

Originally, I think I tried setting response = msgbox but it did not work
becase I left the ( ) out of the msgbox statment.

Regards,

:

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top