ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Message box & close worksheet (https://www.excelbanter.com/excel-programming/392366-message-box-close-worksheet.html)

Jock

Message box & close worksheet
 
Code bolow doesn't close the worksheet when 'no' is chosen rather than yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
--
tia

Jock

Mike H

Message box & close worksheet
 
Jock,

Try this :-

Private Sub CommandButton1_Click()
response = MsgBox("Do you wish to order another item?", vbYesNo)
If response = vbYes Then
MsgBox ("YES")
'TextBox3.SetFocus
Else
ThisWorkbook.Close savechanges:=True
End If
End Sub

Mike

"Jock" wrote:

Code bolow doesn't close the worksheet when 'no' is chosen rather than yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
--
tia

Jock


papou

Message box & close worksheet
 
Hi Jock
The code does not work since your are using a variable which has no value
attached.
You may consider amending:

Private Sub CommandButton1_Click()

response = MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If
End Sub

HTH
Cordially
Pascal


"Jock" a écrit dans le message de news:
...
Code bolow doesn't close the worksheet when 'no' is chosen rather than
yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
--
tia

Jock




Snake Plissken[_2_]

Message box & close worksheet
 


try this:


Private Sub CommandButton1_Click()

Dim response

response = MsgBox("Do you wish to order another item?", vbYesNo)

If response = vbYes Then

TextBox3.SetFocus
exit sub
Else

ThisWorkbook.Close True

End If


End Sub



Incidental

Message box & close worksheet
 
hi Jock

You could do like this

Private Sub CommandButton1_Click()

Response = MsgBox("Do you wish to order another item?", vbYesNo)

If Response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close
End If

End Sub


hope it helps

S



NickHK

Message box & close worksheet
 
Jock,

Private Sub CommandButton1_Click()
Dim Response as long

Response = MsgBox("Do you wish to order another item?", vbYesNo)

If response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If

End Sub

Also, check the Help for "Option Explicit".

NickHK

"Jock" wrote in message
...
Code bolow doesn't close the worksheet when 'no' is chosen rather than

yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
--
tia

Jock




Jock

Message box & close worksheet
 
Many thanks to Mike, Papou, Nick, Snake and Incedental. Job done
Snake, "I heard you were dead" Much better now, I see.lol
--
tia

Jock


"Jock" wrote:

Code bolow doesn't close the worksheet when 'no' is chosen rather than yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
--
tia

Jock


Snake Plissken[_2_]

Message box & close worksheet
 
| Snake, "I heard you were dead" Much better now, I see.lol

the rumours about my death were obviously false :D




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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com