vbno not being recognized as vbno - affecting If statement

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code:
Code:
ui1 = MsgBox("This will end data entry . No data entered will be retained." & Chr(13) & "Are you sure you wish to exit?", vbQuestion + vbYesNo, "CONFIRMATION REQUEST")
Stop
If ui1 = vbNo Then Exit Sub

When the user selects "NO", the code continues beyond the IF statement. The value of ui1 = 6 and vbno = 7? Why the differencesd is values? What do I need to use in my If statement?
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
What data type have you assigned to uil ?
If I add "Dim uil as long" to your code it seem to work fine for me.
 
Upvote 0
I had a "duh" moment.
Disregard this question folks. Moderators may choose to exterminate it.
 
Upvote 0
Thanks Alex. The question was phrased to exit if answered "YES". I had it coded to exit with "NO" as an answer.
 
Upvote 0
Thanks Alex. The question was phrased to exit if answered "YES". I had it coded to exit with "NO" as an answer.

looks like you spotted your own problem but I was going to suggest trying this

VBA Code:
Dim Response As VbMsgBoxResult
Response = MsgBox("This will end data entry . No data entered will be retained." & Chr(13) & _
"Are you sure you wish to exit?", vbQuestion + vbYesNo, "CONFIRMATION REQUEST")
If Response = vbYes Then Exit Sub

Msgbox result has it's own enum: MsgBoxResult Enum (Microsoft.VisualBasic)

which will produce the IntelliSense which you should find tad easier

Dave
 
Upvote 0
Thanks Dave! I will have to investigate that further!!! I always enjoy a new learning opportunity so this post certainly wasn't a waste after all.
 
Upvote 0
You can aslo get rid of the variable completely & just do
VBA Code:
If MsgBox("This will end data entry . No data entered will be retained." & Chr(13) & "Are you sure you wish to exit?", vbQuestion + vbYesNo, "CONFIRMATION REQUEST") = vbYes Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top