View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Kevin Stecyk Kevin Stecyk is offline
external usenet poster
 
Posts: 74
Default restrict entry in a textbox to a range of values

Dan,

You are right!

I need to slow down and read the question.

Regards,
Kevin


"Dan E" wrote in message
...
Dillonstar,

I couldn't find the Data Validation for textboxes so...


Private Sub TextBox1_LostFocus()
Dim TBoxVal As Double
On Error GoTo ErrSec
If TextBox1.Value = "" Then Exit Sub
TBoxVal = CDbl(TextBox1.Value)
If TBoxVal < 9200000000# Or TBoxVal 9299999999# Then
TextBox1.Value = ""
MsgBox Prompt:="Your input was out of the range 9200000000" & _
vbCrLf & "& 9299999999. Please try again!"
TextBox1.Activate
Exit Sub
Else
Exit Sub
End If

ErrSec:
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate
End Sub


Allows the textbox to remain blank, if you don't want this remove the
If TextBox1.Value = "" Then Exit Sub

Does not allow non-numeric entry, if you want to have this remove the
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate

Dan E


"Dillonstar" wrote in message

...
I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/