Yes or No Message Box

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Hello All,

I need a Yes or No message box (which reads: "TEST")
If I choose Yes, then the program runs.
If I choose No, then the program exits, and the program does not run.
Thanks for the help
excel 2013
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Sub test()
Dim ans As Long
ans = MsgBox("Run the program?", vbYesNo, "TEST")
If ans = vbNo Then Exit Sub
'your program code here
End Sub
 
Upvote 0
Something along these lines :
Code:
Sub test()
    If MsgBox("test", vbYesNo) = vbYes Then
        MsgBox "code running."
    End If
End Sub
 
Upvote 0
Code:
ans = MsgBox(" Clearing Sheets Will Delete Any Added Sheets. Select Yes to DELETE ANY ADDED Sheets ", vbYesNo, "TEST")
If ans = vbNo Then Exit Sub

For Each sht In ActiveWorkbook.Worksheets
    If (sht.Name <> "Instructions") And (sht.Name <> "Revisions") And (sht.Name <> "Template") Then
    sht.Select
        With Selection
            ActiveWindow.SelectedSheets.Delete
        End With
    End If
Next sht

Here's My Code, which is working, thank you
Question:
The MsgBox message is quite long, how do I get the message to show on two lines in the message box, instead of one long line?
Thanks for the help
 
Upvote 0
Code:
ans = MsgBox(" Clearing Sheets Will Delete Any Added Sheets. Select Yes to DELETE ANY ADDED Sheets ", vbYesNo, "TEST")
If ans = vbNo Then Exit Sub

For Each sht In ActiveWorkbook.Worksheets
    If (sht.Name <> "Instructions") And (sht.Name <> "Revisions") And (sht.Name <> "Template") Then
    sht.Select
        With Selection
            ActiveWindow.SelectedSheets.Delete
        End With
    End If
Next sht

Here's My Code, which is working, thank you
Question:
The MsgBox message is quite long, how do I get the message to show on two lines in the message box, instead of one long line?
Thanks for the help
You are welcome.

For a two-line msgbox change this

ans = MsgBox(" Clearing Sheets Will Delete Any Added Sheets. Select Yes to DELETE ANY ADDED Sheets ", vbYesNo, "TEST")

to this:
Code:
ans = MsgBox(" Clearing Sheets Will Delete Any Added Sheets." & vbNewLine & "Select Yes to DELETE ANY ADDED Sheets ", vbYesNo, "TEST")
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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