Userform Textbox Criteria

Turbo68

Board Regular
Joined
Jan 31, 2014
Messages
118
I am wanting my textbox that I have named: ISSUE to meet the following parameters:

1. No Alpha at all - If an alpha character is typed instantly say no letters, please.
2. HAS to be a number between 1000000 & 2000000.

I have OnlyNumbers set up already but failing on getting it to check the number of numerals or the between numbers.

Can this be done???

Thanks

Mike
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I have OnlyNumbers set up already but failing on getting it to check the number of numerals or the between numbers.


Mike

Hi,
Helpful if you publish code(s) you have issues with.

One way of checking if a value in Textbox is between certain values is to use the controls Exit event which has the Cancel parameter


Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.TextBox1
      Cancel = CBool(Me.Visible And Len(.Text) > 0 And Not Val(.Text) >= 1000000 And Val(.Text) <= 2000000)
      If Cancel Then MsgBox "Invalid Entry" & Chr(10) & _
                            "Please enter a number between 1000000 & 2000000", 48, "Invalid Entry"
    End With
End Sub



Change the control name as required

Dave
 
Last edited:
Upvote 0
This works if UNDER the 1000000 but will take anything over 2000000?

Private Sub Issue_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.Issue
Cancel = CBool(Me.Visible And Len(.Text) > 0 And Not Val(.Text) >= 1000000 And Val(.Text) <= 2000000)
If Cancel Then MsgBox "Invalid Entry" & Chr(10) & _
"Please enter a number between 1000000 & 2000000", 48, "Invalid Entry"
End With
End Sub
 
Upvote 0
try this update

Code:
Private Sub Issue_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.Issue
    If Me.Visible And Len(.Text) > 0 Then
      Cancel = CBool(Val(.Text) < 1000000 Or Val(.Text) > 2000000)
     End If
    If Cancel Then MsgBox "Invalid Entry" & Chr(10) & _
                            "Please enter a number between 1000000 & 2000000", 48, "Invalid Entry"
    End With
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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