Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
I have made a user form that upon data in three text boxes, it closes and the
data is entered in relevant cell son my worksheet. I then have a command button on the worksheet that re-loads the user form. so far so good What code do I need to ensure only numeric values are accepted in my 3 textboxes? ...and where would I put this code? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
Hi, Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii < 48 Or KeyAscii 57 Then KeyAscii = 0 End If End Sub should do it.. -- Nick ----------------------------------------------------------------------- Nicke's Profile: http://www.excelforum.com/member.php...nfo&userid=293 View this thread: http://www.excelforum.com/showthread.php?threadid=26952 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
Nicke
I tried the code but it didn't work. I put in inbetween:- Private Sub TextBox2_Change() End Sub Any suggestions? "Nicke" wrote: Hi, Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If KeyAscii < 48 Or KeyAscii 57 Then KeyAscii = 0 End If End Sub should do it... -- Nicke ------------------------------------------------------------------------ Nicke's Profile: http://www.excelforum.com/member.php...fo&userid=2930 View this thread: http://www.excelforum.com/showthread...hreadid=269520 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
Look at my code, its in the *KEYPRESS * event -- Nicke ------------------------------------------------------------------------ Nicke's Profile: http://www.excelforum.com/member.php...fo&userid=2930 View this thread: http://www.excelforum.com/showthread...hreadid=269520 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
Hi Anthony:
'This is also a way to test the input. '/// Place the following on the Sheet Private Sub CommandButton1_Click() With UserForm1 .Show .TextBox1.SelStart = 0 .TextBox1.SelLength = Len(.TextBox1.Text) .TextBox1.SetFocus End With End Sub '/// This is on the Userform Private Sub CommandButton1_Click() If IsNumeric(TextBox1.Text) Then TextBox1.Text = TextBox1.Text MsgBox "Your Number is " & TextBox1.Text, , _ "Good Luck TK" UserForm1.Hide Else MsgBox "Please enter a valid Number " With TextBox1 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With End If Exit Sub End Sub 'Good Luck TK |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Inputting numbers only in Text Box
Hi Anthony:
After re-reading your post, I included code for the other textboxes. "/// paste the following to your userform Private Sub CommandButton1_Click() If IsNumeric(TextBox1.Text) Then TextBox1.Text = TextBox1.Text MsgBox "1 Your Number is " & TextBox1.Text, , _ "Good Luck TK" 'UserForm1.Hide Else MsgBox "1 Please enter a valid Number " With TextBox1 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With Exit Sub End If If IsNumeric(TextBox2.Text) Then TextBox2.Text = TextBox2.Text MsgBox "2 Your Number is " & TextBox2.Text, , _ "Good Luck TK" 'UserForm1.Hide Else MsgBox "2 Please enter a valid Number " With TextBox2 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With Exit Sub End If If IsNumeric(TextBox3.Text) Then TextBox3.Text = TextBox3.Text MsgBox "3 Your Number is " & TextBox3.Text, , _ "Good Luck TK" UserForm1.Hide Else MsgBox "3 Please enter a valid Number " With TextBox3 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With End If Exit Sub End Sub Good Luck TK "TK" wrote: Hi Anthony: 'This is also a way to test the input. '/// Place the following on the Sheet Private Sub CommandButton1_Click() With UserForm1 .Show .TextBox1.SelStart = 0 .TextBox1.SelLength = Len(.TextBox1.Text) .TextBox1.SetFocus End With End Sub '/// This is on the Userform Private Sub CommandButton1_Click() If IsNumeric(TextBox1.Text) Then TextBox1.Text = TextBox1.Text MsgBox "Your Number is " & TextBox1.Text, , _ "Good Luck TK" UserForm1.Hide Else MsgBox "Please enter a valid Number " With TextBox1 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With End If Exit Sub End Sub 'Good Luck TK |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
help with inputting code | New Users to Excel | |||
Having trouble inputting numbers past 09 it shows 0.10 in excel | Excel Discussion (Misc queries) | |||
Inputting numbers using a macro. | Excel Discussion (Misc queries) | |||
inputting data | Excel Discussion (Misc queries) | |||
Auto fill text boxes in user form by inputting data in another | Excel Programming |