Msg box w/ cancel option

boxsterman

Active Member
Joined
Apr 16, 2002
Messages
279
Hi all,

I have the standard message box in my code

msgbox ("Continue?")

How do I include with with a cancel option - I want to give the user the option to abort the VBA script if they haven't completed a task.

Thanks,

J
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,945
Office Version
  1. 365
Platform
  1. Windows
Check out the second argument of MsgBox in VBA help, it gives you a list of options to choose, i.e.

MsgBox "Continue", vbOKCancel
will display both "OK" and "Cancel"
 

boxsterman

Active Member
Joined
Apr 16, 2002
Messages
279
Hi - thanks for the tip,

However when I press cancel, it still continues with the VBA script - I need it to cance when cancel is selected.

J.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,945
Office Version
  1. 365
Platform
  1. Windows
Here is a little script that displays how you can handle the reply:
Code:
    Dim myReply
    myReply = MsgBox("Continue", vbOKCancel)
    If myReply = vbOK Then
        MsgBox "Continuing on..."
    Else
        MsgBox "Process cancelled"
    End If
 

Forum statistics

Threads
1,141,012
Messages
5,703,729
Members
421,312
Latest member
Mooncake1

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
Top