text box entry format

  • Thread starter Thread starter mark kubicki
  • Start date Start date
M

mark kubicki

is ther an easy way to limit the entry into a text box to ONLY be numneric
(alpha can't be entered at all).
and then a second question: cold the numeric be given an automatic format
(ex: ###0.00)
 
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

End Sub
 
You can use the click event to test the keystroke and
cancel it if it's not a number, like this:

Private Sub TextBox1_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
If KeyAscii > 47 And KeyAscii < 58 Then KeyAscii = 0
End Sub

This is the XP version. I don't know if the Excel 2000
uses the same arguments.
 
It's easy to trap the input, like so

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

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top