ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Textbox accepts alpha only (https://www.excelbanter.com/excel-programming/336104-textbox-accepts-alpha-only.html)

LeLi

Textbox accepts alpha only
 
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!


Patrick Molloy[_2_]

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!



LeLi

Textbox accepts alpha only
 
thanks Patrick!



All times are GMT +1. The time now is 01:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com