#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Textbox

How do I make sure that whatever is entered in a textbox on a userform is a
letter of the alphabet or a number only?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Textbox

try something like this

Function TestString(TestStr As String)

TestString = True
If Not IsNumeric(TestStr) Then
For i = 1 To Len(TestStr)
TestChar = UCase(Mid(TestStr, i, 1))

If Asc(TestChar) < Asc("A") Or _
Asc(TestChar) Asc("Z") Then

TestString = False
Exit For
End If
Next i
End If

End Function

"ranswrt" wrote:

How do I make sure that whatever is entered in a textbox on a userform is a
letter of the alphabet or a number only?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Textbox

I just made some modifications to Joel post. Since you only want Letters and
Numbers in the textbox it will probably be very useful to use a
AfterUpdate_Event. This will test the Text in the Textbox once the Textbox
looses its focus. I added a message box as well.

Private Sub TextBox1_AfterUpdate()

Dim TestStr As String
Dim I As Integer
Dim TestChar As String

TestStr = TextBox1.Text

For I = 1 To Len(TestStr)
TestChar = UCase(Mid(TestStr, I, 1))

If Not IsNumeric(TestChar) Then
If Asc(TestChar) < Asc("A") Or _
Asc(TestChar) Asc("Z") Then
MsgBox "You need to enter Letters & Numbers only!", vbExclamation
Exit For
End If
End If
Next I

End Sub

Hope this helps!
--
Cheers,
Ryan


"ranswrt" wrote:

How do I make sure that whatever is entered in a textbox on a userform is a
letter of the alphabet or a number only?
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Textbox

Thanks I'll give that a try

"RyanH" wrote:

I just made some modifications to Joel post. Since you only want Letters and
Numbers in the textbox it will probably be very useful to use a
AfterUpdate_Event. This will test the Text in the Textbox once the Textbox
looses its focus. I added a message box as well.

Private Sub TextBox1_AfterUpdate()

Dim TestStr As String
Dim I As Integer
Dim TestChar As String

TestStr = TextBox1.Text

For I = 1 To Len(TestStr)
TestChar = UCase(Mid(TestStr, I, 1))

If Not IsNumeric(TestChar) Then
If Asc(TestChar) < Asc("A") Or _
Asc(TestChar) Asc("Z") Then
MsgBox "You need to enter Letters & Numbers only!", vbExclamation
Exit For
End If
End If
Next I

End Sub

Hope this helps!
--
Cheers,
Ryan


"ranswrt" wrote:

How do I make sure that whatever is entered in a textbox on a userform is a
letter of the alphabet or a number only?
Thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox from 1st worksheet to textbox to other multiple sheets LRay67 Excel Programming 2 March 18th 08 02:20 PM
HELP! I Lost The Ability To Advance From TextBox To TextBox With the ENTER Or The TAB Keys Minitman[_4_] Excel Programming 0 February 22nd 05 08:50 PM
Textbox Bug? Missing/delayed update of textbox filled via VBA MarcM Excel Programming 0 November 4th 04 05:47 PM
Textbox Bug? Missing/delayed update of textbox filled via VBA MarcM Excel Programming 0 November 4th 04 05:43 PM
How to move cursor from one textbox control to another textbox con Tom Ogilvy Excel Programming 1 September 16th 04 03:42 PM


All times are GMT +1. The time now is 07:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"