Select Case not picking up number

jrwrangler

New Member
Joined
Mar 22, 2013
Messages
16
I am using an input box with select case. I want it to let values that are under 100 and end in a zero to proceed to a msgbox that offers a reminder. For Any values that do not have a zero as the second digit to pop up an error message that lets them retry by going through the code again. When I enter values like 123 it still proceeds. Values like 12 gives me the first message box. I don't know why this is

Code:
ReTryIt2:
NumShares = Application.InputBox(prompt:="Please Enter The TOTAL Number of Shares Being Covered Today: " Title:="Shares Being Covered TODAY")
Select Case NumShares
Case Is < 100 And Mid(NumShares, 2, 1) = 0
MsgBox ("Ok, Looks Good.....")
Case Mid(NumShares, 2, 1) <> 0
MsgBox ("This Is An Invalid Entry.Please Retry")
GoTo ReTryIt2
End Select
Code:
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Force the result as integer then it should work;

Code:
Numshares = Application.InputBox(prompt:="Please Enter The TOTAL Number of Shares Being Covered Today: ", Title:="Shares Being Covered TODAY")
 
 Numshares = Int(Numshares)
 
 Select Case Numshares
 
 Case Is < 100 And Mid(Numshares, 2, 1) = 0
    MsgBox ("Ok, Looks Good.....")
 
Case Is > 0 And Mid(Numshares, 2, 1) <> 0
    MsgBox ("This Is An Invalid Entry.Please Retry")
  Goto ReTryIt2

 End Select
 
Upvote 0
Few points,

1) No code tags is always bad on this forum
2) Using GoTo like this is bad coding practise
3) I don't think Select Case can be used like that, but I like to be proven wrong.

With those in mind give this a try:
Code:
Dim NumShares As Integer
Dim bGood As Boolean


bGood = False


Do While bGood = False
    NumShares = Application.InputBox(prompt:="Please Enter The TOTAL Number of Shares Being Covered Today: ", Title:="Shares Being Covered TODAY")
    
    If NumShares < 100 And Right(CStr(NumShares), 1) = "0" Then
        MsgBox "OK Looks Good"
        bGood = True
    Else
        MsgBox ("This Is An Invalid Entry.Please Retry")
    End If
Loop
 
Upvote 0

Forum statistics

Threads
1,203,077
Messages
6,053,398
Members
444,661
Latest member
liamoohay

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