Thread: If end sub
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default If end sub

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

"Miree" wrote:

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

"Mike H" wrote:

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

"Miree" wrote:

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