View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default VBA data validation

Sorry about the following, but it is Sunday and things are kind of slow
around here.<g

Why so many lines of code?

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = -KeyAscii * (Len(TextBox1.Text) < 6 And _
Chr(KeyAscii) Like "#" And KeyAscii < 8)
End Sub

--
Rick (MVP - Excel)



"Chip Pearson" wrote in message
...
Use code like the following:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Len(Me.TextBox1.Text) = 6 Then
KeyAscii = 0
Else
Select Case KeyAscii
Case Asc("0") To Asc("9")
' OK
Case Else
KeyAscii = 0
End Select
End If

End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Sat, 8 May 2010 01:22:24 -0700 (PDT), KK wrote:

Hi all,
I have created a textbox input on a userform. I would like to input
the postal code here and would like to dala validate it for a 6
numeric input. Is ther a way to do this