Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Disable/Prevent Letters or Numbers in textbox
Hello, I'm sure you have answered this a thousand times but I done little search and couldn't find what I was looking for. What I am after is a text box which does not allow letters to b entered into it. I have seen a few codes which check for letters afte the box has been filled but I want one where the user can press letter key and nothing happens in the box i.e it only responds t numbers. Any help would be greatly appreciated. Thanks Joh -- johncassel ----------------------------------------------------------------------- johncassell's Profile: http://www.excelforum.com/member.php...fo&userid=2501 View this thread: http://www.excelforum.com/showthread.php?threadid=39016 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Disable/Prevent Letters or Numbers in textbox
Your tickets are the keypress event and the sendkeys method. Use some code like: Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If Not (KeyAscii = 48 And KeyAscii <= 57) Then ' not a digit Range("B17").Value = KeyAscii SendKeys ("{BS}") 'send backspace End If End Sub What it does is sends a backspace character immediately after any non-digit character. -- TommySzalapski ------------------------------------------------------------------------ TommySzalapski's Profile: http://www.excelforum.com/member.php...o&userid=25561 View this thread: http://www.excelforum.com/showthread...hreadid=390166 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Disable/Prevent Letters or Numbers in textbox
Thanks very much for that Tommy, precisely what I was after and thank for replying so fast -- johncassel ----------------------------------------------------------------------- johncassell's Profile: http://www.excelforum.com/member.php...fo&userid=2501 View this thread: http://www.excelforum.com/showthread.php?threadid=39016 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Disable/Prevent Letters or Numbers in textbox
As a matter of general interest, this too works: validates onl non-numeric characters. Private Sub TextBox1_Enter() Call chk End Sub Sub chk() For Each ctl In UserForm1.Controls If TypeName(ctl) = "TextBox" Then If IsNumeric(ctl) Then ctl.Text = "" End If End If Next End Su -- david ----------------------------------------------------------------------- davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064 View this thread: http://www.excelforum.com/showthread.php?threadid=39016 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Disable/Prevent Letters or Numbers in textbox
True, but then the question is does he mean just the digits 0 to 9
? isnumeric("02,21,14.23") True ? isnumeric("35E1") True ? isnumeric("34D1") True Also, why the Enter event? -- Regards, Tom Ogilvy "davidm" wrote in message ... As a matter of general interest, this too works: validates only non-numeric characters. Private Sub TextBox1_Enter() Call chk End Sub Sub chk() For Each ctl In UserForm1.Controls If TypeName(ctl) = "TextBox" Then If IsNumeric(ctl) Then ctl.Text = "" End If End If Next End Sub -- davidm ------------------------------------------------------------------------ davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645 View this thread: http://www.excelforum.com/showthread...hreadid=390166 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Custom Formating Letters to Numbers while Displaying Letters | Excel Worksheet Functions | |||
Columns now numbers rather than letters how do i get letters back | Excel Discussion (Misc queries) | |||
Count only Letters in cells that contain both letters and numbers | Excel Worksheet Functions | |||
Sorting - cells containing numbers, numbers and letters | Excel Discussion (Misc queries) | |||
create self-generating numbers with letters and numbers | Excel Discussion (Misc queries) |