Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Karina K patni   on Dec 20 In MS Office Category.

  
Question Answered By: Cesara Fernandez   on Dec 20

The following VBA code attached to a textbox will allow entry of digits (0 to 9)
only. Change TextBox1 throughout to the name of your textbox.

Private Sub TextBox1_Change()
If Len(TextBox1.Text) > 0 Then
TextBox1.Text = NbrOnly(TextBox1.Text)
End If
End Sub

Private Function NbrOnly(Intxt As String) As String
Dim zz As Long, OutStr As String
For zz& = 1 To Len(Intxt$)
Select Case Mid(Intxt$, zz&, 1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
OutStr$ = OutStr$ & Mid(Intxt$, zz&, 1)
Case Else
'do nothing
End Select
Next zz&
NbrOnly$ = OutStr$
End Function

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on text box -- integers only Or get search suggestion and latest updates.


Tagged: