Exit Macro if NO is choosen from Msgbox

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
I have this code.

Dim ws As Worksheet

For Each ws In Sheets
If ws.Name = "Test" Then
ws.Select
Application.DisplayAlerts = False
Message = MsgBox("Delete " & ws.Name & " sheet?", vbYesNo, "ARE YOU SURE ABOUT THIS?")
'Does not require End If statement
If Message = vbYes Then Worksheets(ws.Name).Delete
End If
Next ws

- more code-

End Sub

How do I get it to exit the macro if the use chooses NO instead of YES?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
<pre>
If Message = vbYes Then
Worksheets(ws.Name).Delete
else
exit sub 'or STOP if you have additional subroutines running
End If </pre>
 
Upvote 0
I am afriad I don't know what you mean by additional sub-routines!

Please excuse my ignorance!
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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