Validating Entry into Textbox

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

Hi all,

I've created a custom userform with many textboxes in
Excel 2000. I'd like to validate/limit the values that
can be entered into these text boxes. If the entered
value is outside of the desired range, it should prevent
the user from continuing. This is what I have so far:

Private Sub TextBox1_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
Set ControlName = TextBox1
Call CheckIntEntry(ControlName, Cancel)
End Sub

Sub CheckIntEntry(ControlName, Cancel)
If ControlName.Value < 0 Or ControlName.Value > 999
Then
Cancel = True
MsgBox ("Entry must be between 0 and 999.")
Else
Cancel = False
End If
End Sub

This does what I want, but would have to be setup for the
50+ textboxes. Is there a better way to limit entry? Can
a property be set for each textbox that sets an allowable
entry range? Thanks in advance for your help.

-Brad
 
Back
Top