ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   textbox character limits (https://www.excelbanter.com/excel-programming/332868-textbox-character-limits.html)

dok112[_38_]

textbox character limits
 

Hey everyone...quick question....is there a way to limit a textbox on
form to only accept numbers? I don't want a user to be able to ente
any characters except 0-9..

--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=38231


cadcamguy

textbox character limits
 
One way... and I sure there is a more excel type way is

this will allow decimal point also


Private Sub textbox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If CheckBox2.Value = True Then
If KeyAscii 47 And KeyAscii < 58 Then ' 0 to 9
KeyAscii = KeyAscii
ElseIf KeyAscii = 8 Or KeyAscii = 13 Or KeyAscii = 46 Then ' backspace
and enter keys
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End If
End Sub



cadcamguy

textbox character limits
 
forgot the checkbox part as I added that to give option of number only or
alphas



Norman Jones

textbox character limits
 
Hi Dok112,

See:

http://tinyurl.com/cp6oh

and

http://tinyurl.com/8rnvr


---
Regards,
Norman



"dok112" wrote in
message ...

Hey everyone...quick question....is there a way to limit a textbox on a
form to only accept numbers? I don't want a user to be able to enter
any characters except 0-9...


--
dok112
------------------------------------------------------------------------
dok112's Profile:
http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=382315





All times are GMT +1. The time now is 08:43 AM.

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