ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,655
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have the code in use shown below.

Can you advise what ive missed please as when i select No the code still runs as opposed to exit.
Yes should continut but No should exit

Code:
Private Sub CommandButton1_Click()MsgBox "Did You Select The Vehicle?", vbYesNo + vbInformation, "Vehicle Selection Checker"
If vbYes Then


Sheets("Sheet1").Range("P6:U6").Copy Sheets("Sheet1").Range("E6")
Sheets("Sheet1").Range("P7").Copy Sheets("Sheet1").Range("E7")


Sheets("Sheet1").Range("E6:J6").Copy Sheets("DR SITE").Range("E6")
Sheets("Sheet1").Range("E7").Copy Sheets("DR SITE").Range("E7")


Sheets("Sheet1").Range("E6:J6").Copy Sheets("EBAY").Range("E6")
Sheets("Sheet1").Range("E7").Copy Sheets("EBAY").Range("E7")


Sheets("DR SITE").Range("E7").Font.Color = vbWhite
Sheets("DR SITE").Range("E7").Borders.LineStyle = xlNone




Sheets("EBAY").Range("E7").Font.Color = vbWhite
Sheets("EBAY").Range("E7").Borders.LineStyle = xlNone




Sheets("DR SITE").Activate
ActiveSheet.Range("E7").Select


Sheets("EBAY").Activate
ActiveSheet.Range("E7").Select


Sheets("Sheet1").Activate
ActiveSheet.Range("P6").Select


ActiveWorkbook.Save
End If


End Sub
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,334
Office Version
  1. 2010
Platform
  1. Windows
You have to assign the output from the MessageBox to a variable and then test that variable against the vbYes constant. So, instead of this...
Code:
[table="width: 500"]
[tr]
	[td]MsgBox "Did You Select The Vehicle?", vbYesNo + vbInformation, "Vehicle Selection Checker"
If vbYes Then[/td]
[/tr]
[/table]
use something like this...
Code:
[table="width: 500"]
[tr]
	[td]Dim Answer As Long
Answer = MsgBox("Did You Select The Vehicle?", vbYesNo + vbInformation, "Vehicle Selection Checker")
If Answer = vbYes Then[/td]
[/tr]
[/table]
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,109,501
Messages
5,529,238
Members
409,857
Latest member
KailuaTown
Top