ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   only letters in text box (https://www.excelbanter.com/excel-programming/344400-only-letters-text-box.html)

JNW

only letters in text box
 
I know about the IsNumber function. I was wondering if there is a similar
function to only allow letters in the text box. The IsText worksheet
function won't cut it.

Thanks!

Harald Staff

only letters in text box
 
This allows keyboard entries space, A-Z and a-z only:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 32, 65 To 90, 97 To 122
Case Else
KeyAscii = 0
End Select
End Sub

See or make a character map for other allowed characters and symbols. This
does not handle Ctrl V, do that with code in the KeyDown event if required.

HTH. Best wishes Harald.

"JNW" skrev i melding
...
I know about the IsNumber function. I was wondering if there is a similar
function to only allow letters in the text box. The IsText worksheet
function won't cut it.

Thanks!




Jim Rech

only letters in text box
 
There is no Excel worksheet or VB function that can directly tell you if a
string has any numeric characters. You could use this perhaps:

Sub TestOK()
MsgBox StrHasNoNums("abc")
End Sub

Sub TestBad()
MsgBox StrHasNoNums("a2c")
End Sub

Function StrHasNoNums(Str As String) As Boolean
Dim Counter As Integer
Dim ThisChar As String
For Counter = 1 To Len(Str)
ThisChar = Mid(Str, Counter, 1)
If ThisChar <= "9" Then
If ThisChar = "0" Then Exit Function
End If
Next
StrHasNoNums = True
End Function


--
Jim
"JNW" wrote in message
...
|I know about the IsNumber function. I was wondering if there is a similar
| function to only allow letters in the text box. The IsText worksheet
| function won't cut it.
|
| Thanks!




All times are GMT +1. The time now is 03:42 AM.

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