ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Textbox format (https://www.excelbanter.com/excel-programming/325818-textbox-format.html)

Greg B[_4_]

Textbox format
 
How do I get a textbox to only allow numbers

Thanks in advance

Greg



papou

Textbox format
 
Hi Greg
You could use the Keypress event from your textbox and then using the
KeyAscii, check each input allowing only numbers.
HTH
Cordially
Pascal

"Greg B" a écrit dans le message de
...
How do I get a textbox to only allow numbers

Thanks in advance

Greg





Greg B[_4_]

Textbox format
 
Sorry to be a pain how do I do that?

Thanks again

Greg




Bob Phillips[_6_]

Textbox format
 
Greg,

This allows numbers, - and .. Adjust to suit

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57 'Nos 0 - 9
Exit Sub
Case 45, 46 ' - and .
Exit Sub
Case Else
Application.EnableEvents = False
KeyAscii = 0
Application.EnableEvents = True
Beep
End Select


End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Greg B" wrote in message
...
Sorry to be a pain how do I do that?

Thanks again

Greg






Greg B[_4_]

Textbox format
 
thanks Bob for your help

Greg





All times are GMT +1. The time now is 10:35 AM.

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