Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


Numeric Text Box

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
pk



Joined: 17 Aug 2008
Posts: 1

PostPosted: Sun Aug 17, 2008 12:09 pm    Post subject: Numeric Text Box Reply with quote

Hi everybody,

I need a vba code for restricting the input to numbers only on a TextBox.
(Numbers with or without decimal point)


Thanks in adnvace
Back to top
View user's profile Send private message
mohan.ankur
Moderator
Moderator


Joined: 02 Aug 2006
Posts: 52

PostPosted: Tue Aug 19, 2008 1:59 pm    Post subject: Restricitng to Numbers Reply with quote

Private Sub TextBox1_Change()
Dim okstop As Boolean
Dim OK_continue As Boolean
Dim mytext As String

okstop = False


Do
mytext = TextBox1.Value
If Left(mytext, 1) = "-" Then
mytext = Right(mytext, Len(mytext) - 1)
End If
If Not IsNumeric(mytext) And mytext <> "" Then
TextBox1.Value = "" 'Clears the TextBox


'Shows a message box that informs you that you typed
'something other than a number.
OK_continue = MsgBox("Please type only numbers." & _
Chr(13), vbOKOnly)
Else
okstop = True 'You typed a number in the TextBox.
End If


'Continue with the loop if you click Yes.
'Stop the loop if they typed a number in the TextBox.
Loop Until (OK_continue = vbNo) Or (okstop = True)


End Sub


Try the code above...

Hope it helps

Ankur
_________________
http://www.exceldepot.com
http://www.xlmacros.com
http://www.learnexcel.org
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group