Is it possible to validate date in Visual Basic Editor? If so how.

G

Guest

I am trying to set up a validation method for a text box in Visual Basic
Editor. I need to validate the cell so that it is 11 digits long and only
contains numbers, if possible it must have a 0 at the beginning, though this
is not compulsory. This validation is for a telephone number, but i have not
found any way to validate the box apart from maximum text length. Any help
would be appreciated a lot, thanks.
 
B

Bob Phillips

Matt,

Try this

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With TextBox1
If Len(.Text) = 11 Then
KeyAscii = 0
ElseIf Len(.Text) = 0 Then
If KeyAscii <> 48 Then
KeyAscii = 0
End If
ElseIf Not IsNumeric(Asc(KeyAscii)) Then
KeyAscii = 0
End If
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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

Top