If end sub

M

Miree

So far I have the following code, It needs to carry out the furthur code if
Yes or No selected, I want the selection of Cancel to just close msg box and
end the sub.

Response = MsgBox("Do you want to Print?", vbYesNoCancel)
If Response = vbYes Then
Range("A1:K41").PrintOut

End If

furthur code
 
M

Mike H

Hi,

Try this

Sub Marine()
response = MsgBox("Do you want to Print?", vbYesNoCancel)
If response = vbYes Then
Range("A1:K41").PrintOut
ElseIf response = vbNo Then
MsgBox "You pressed no"
'Do things
ElseIf response = vbCancel Then
MsgBox "You pressed cancel"
'do different things
End If

End Sub

Mike
 
M

Mike H

Sorry missed the bit about exit sub

Sub Marine()
response = MsgBox("Do you want to Print?", vbYesNoCancel)
If response = vbYes Then
Range("A1:K41").PrintOut
ElseIf response = vbNo Then
MsgBox "You pressed no"
'Do things
ElseIf response = vbCancel Then
MsgBox "You pressed cancel"
Exit Sub
End If

End Sub
 
M

Miree

This doesn't really help

The furthur code is quite large and needs to run for both yes and no, after
printing.

I just need to exit the sub if user selects cancel
 
M

Mike H

For that you only need to check the cancel button.

Sub Marine()
response = MsgBox("Whatever message you want", vbYesNoCancel)
If response = vbCancel Then
Exit Sub
End If
'lots on lots of code
End Sub

Mike
 

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