Message Box Question

DDH

Well-known Member
Joined
Sep 25, 2003
Messages
513
Is it possible to have three options on the message box?
A option to go back to the top of the sheet (A1)
after you say Yes or No or the search name is not found.
Thank you for your help.

If MsgBox("Continue?", vbYesNo) <> vbNo Then
GoTo Flag1




Sub Search()
Dim vResult1, vResult2
Dim rFound As Range
Dim Lookfor As String

Lookfor = InputBox("Enter Name", "Search")
If Lookfor = "" Then
End
End If

On Error Resume Next
With Sheet1.Range("a:a") 'Sheet1 is the CodeName
Set rFound = .Find _
(What:=Lookfor, After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole)
End With

Flag1:
If Not Cells.Find(What:=Lookfor, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False) Is Nothing Then

Cells.Find(What:=Lookfor, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

If MsgBox("Continue?", vbYesNo) <> vbNo Then
GoTo Flag1
End If

Else
MsgBox ("The Name Was Not Found")

End If
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
There's vbYesNoCancel if that works for you (also vbAbortRetryIgnore).

If you want custom labels on your buttons you'll need to go the user form route.
 
Upvote 0
Code:
MyMsg$ = "Continue?" & vbLf & vbLf & "Yes = Find next" & vbLf & "No = Stop search" & vbLf & "Cancel = Return to A1"

Select Case MsgBox(MyMsg, vbYesNoCancel)
Case vbYes: GoTo Flag1
Case vbNo:
Case vbCancel: Range("A1").Select
End Select
 
Upvote 0
CWatts & AlphaFrog - Thank you for your help.
I tried this and I must have messed something up
because I could not make it work.
 
Upvote 0
Go the user form route. That way you can set up your own buttons. I hadn't messed with them at all and i was able to easily whip one together and they work great. Just set it up with three buttons, double click on a button to assign the code you want to run in the user form, and just put something like UserFormName.Close at the end so the window closes if you want.

I just made two boxes and this is the code:

Code:
Private Sub btnNO_Click()
[a1].Value = "No"
ufYesNo.Hide
End Sub

Private Sub btnYES_Click()
[a1].Value = "Yes"
ufYesNo.Hide
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,835
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top