View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Validating Entry into Textbox

If you want to use the exit event, that would be the way.

--
Regards,
Tom Ogilvy


"Brad" wrote in message
...
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