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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top