Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
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
Custom Formating Letters to Numbers while Displaying Letters Luke Androsiglio Excel Worksheet Functions 2 March 31st 10 06:29 PM
Columns now numbers rather than letters how do i get letters back SalExcel10 Excel Discussion (Misc queries) 2 March 4th 10 02:48 PM
Count only Letters in cells that contain both letters and numbers TommyB Excel Worksheet Functions 2 August 8th 09 12:29 AM
Sorting - cells containing numbers, numbers and letters Gunny Excel Discussion (Misc queries) 5 July 16th 06 01:22 AM
create self-generating numbers with letters and numbers cxlough41 Excel Discussion (Misc queries) 11 January 4th 06 01:16 AM


All times are GMT +1. The time now is 12:19 AM.

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

About Us

"It's about Microsoft Excel"