Userform Value <>

drc2265

Board Regular
Joined
Jul 30, 2007
Messages
96
Hello,

I currently have the following:

Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox9.Value Like "*[!0-9]*" Then
MsgBox "You must provide a numeric value in this TextBox!"
Cancel = True
ElseIf TextBox9.Value > 2 Then
MsgBox "Invalid Pick!"
Cancel = True
ElseIf TextBox9.Value < 1 Then
MsgBox "Invalid Pick!"
Cancel = True
End If
End Sub

I would like to add to this that the only other accepted value would be 999. So only values entered can be 1, 2, or 999.
Appreciate any help.

Thanks,
DC
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I see you have posted this same similar question here twice now tonight.

Please just tell me what your wanting to do and I will see if I can help you.

Are you saying only 1 2 or 999 can be entered into the textbox?
If anything else is entered show a message box.
 
Upvote 0
Try this:
Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Modified  9/11/2018  9:10:51 PM  EDT
If TextBox2.Value <> 1 And TextBox2.Value <> 2 And TextBox2.Value <> 999 Then
    MsgBox "Your only allowed to enter 1 2 or 999" & vbNewLine & "You entered  " & TextBox2.Value
End If
End Sub
 
Upvote 0
Works great thank you! Is there any way to setfocus on the textbox that had the invalid entry? It is currently going to the next textbox for entry.
Thanks again!!
 
Upvote 0
Try this:
Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Modified  9/18/2018  9:46:51 PM  EDT
If TextBox2.Value <> 1 And TextBox2.Value <> 2 And TextBox2.Value <> 999 Then
    MsgBox "Your only allowed to enter 1 2 or 999" & vbNewLine & "You entered  " & TextBox2.Value
    Cancel = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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