#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default If end sub

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If end sub

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If end sub

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

"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default If end sub

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"