View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Textbox accepts alpha only

use the textbox's key press to trap and test which key was pressed.
The code below will allow a space, a hyphen, uppercase and lowercase letter
only. Anything else, then keyascii is set to 0, so nothing gets added to the
text

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 32, 45, 65 To 90, 97 To 122
''do nothing, these are OK
Case Else
' clear the key, we don't want it
KeyAscii = 0
End Select
End Sub

"LeLi" wrote:

hello there! i have this 3 textboxes then what i want to do is to
accept alpha only..because my textbox labeled as the name of a person.
thanks!