ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Digits in textbox's (https://www.excelbanter.com/excel-discussion-misc-queries/43820-digits-textboxs.html)

Greg B

Digits in textbox's
 
Hi all just wondering how I can get someone only to type number in a certain
textbox?

Thanks in advance

Greg



Vasant Nanavati

Is this a TextBox on a UserForm?

Somewhat crude, but try the following:

Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1.Text) Then _
SendKeys "{BACKSPACE}"
End Sub

--

Vasant




"Greg B" wrote in message
...
Hi all just wondering how I can get someone only to type number in a
certain
textbox?

Thanks in advance

Greg





Greg B

Thank you for that

Greg
"Vasant Nanavati" <vasantn AT aol DOT com wrote in message
...
Is this a TextBox on a UserForm?

Somewhat crude, but try the following:

Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1.Text) Then _
SendKeys "{BACKSPACE}"
End Sub

--

Vasant




"Greg B" wrote in message
...
Hi all just wondering how I can get someone only to type number in a
certain
textbox?

Thanks in advance

Greg







Chip Pearson

Better than SendKeys, use the KeyPress event.


Private Sub TextBox1_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii 57 Then
KeyAscii = 0
End If
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Vasant Nanavati" <vasantn AT aol DOT com wrote in message
...
Is this a TextBox on a UserForm?

Somewhat crude, but try the following:

Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1.Text) Then _
SendKeys "{BACKSPACE}"
End Sub

--

Vasant




"Greg B" wrote in message
...
Hi all just wondering how I can get someone only to type
number in a certain
textbox?

Thanks in advance

Greg







Vasant Nanavati

Hi Chip:

I knew there was a better solution but just couldn't get my brain to come up
with it <g.

Regards,

Vasant

"Chip Pearson" wrote in message
...
Better than SendKeys, use the KeyPress event.


Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii 57 Then
KeyAscii = 0
End If
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Vasant Nanavati" <vasantn AT aol DOT com wrote in message
...
Is this a TextBox on a UserForm?

Somewhat crude, but try the following:

Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1.Text) Then _
SendKeys "{BACKSPACE}"
End Sub

--

Vasant




"Greg B" wrote in message
...
Hi all just wondering how I can get someone only to type number in a
certain
textbox?

Thanks in advance

Greg










All times are GMT +1. The time now is 11:09 PM.

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