textbox character limits

  • Thread starter Thread starter dok112
  • Start date Start date
D

dok112

Hey everyone...quick question....is there a way to limit a textbox on
form to only accept numbers? I don't want a user to be able to ente
any characters except 0-9..
 
One way... and I sure there is a more excel type way is

this will allow decimal point also


Private Sub textbox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If CheckBox2.Value = True Then
If KeyAscii > 47 And KeyAscii < 58 Then ' 0 to 9
KeyAscii = KeyAscii
ElseIf KeyAscii = 8 Or KeyAscii = 13 Or KeyAscii = 46 Then ' backspace
and enter keys
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End If
End Sub
 

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