Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default 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   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default 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
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
help with inputting code Morgan New Users to Excel 3 February 26th 10 12:24 AM
Having trouble inputting numbers past 09 it shows 0.10 in excel scary Excel Discussion (Misc queries) 4 May 14th 08 05:37 PM
Inputting numbers using a macro. wazcaster Excel Discussion (Misc queries) 1 September 10th 07 11:38 AM
inputting data Shanor Excel Discussion (Misc queries) 0 June 15th 06 10:50 AM
Auto fill text boxes in user form by inputting data in another Finny33 Excel Programming 1 September 13th 04 12:53 PM


All times are GMT +1. The time now is 08:59 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"