Visual Basic Validation

bt504

New Member
Joined
Nov 10, 2005
Messages
1
I'm struggling to create a validation check on visual basic. I am currently using an input form on VB which copies the information entered on the form onto a cell on a sheet on Excel.

I have 2 areas where a number is typed, in both are textboxes. I need to have a validation check to check the range (0-50) and to check the value entered is a number and is an integer.

I cannot use the validation checks used on cells in Excel as I am using an input form on VB.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this:

Code:
Private Sub TextBox1_Change()
    Dim Char As String
    Char = UCase(Right(TextBox1.Text, 1))
    If Char Like "#" And Val(TextBox1.Text) <= 50 Then
        Exit Sub
    Else
        Beep
        MsgBox "Please enter an integer in the range 0 to 50"
        On Error Resume Next
        TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
        TextBox1.SelStart = Len(TextBox1.Text)
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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