Numeric-only textbox

Allow only Currency into textbox, text box will allow only nnnn.nn where n=1 through 9
Paste below in your userform code renaming a textbos to "txtAmount"

CodeFunctionName
What is this?

Public

Tested

Original Work
Private Sub txtAmount_KeyPress(KeyAscii As Integer)
If Len(txtAmount.Text) > 14 Then
KeyAscii = 0
End If
If KeyAscii = 8 Then Exit Sub
If InStr(1, txtAmount.Text, ".") < > 0 And KeyAscii = 46 Then
KeyAscii = 0
ElseIf InStr(1, txtAmount.Text, ".") < > 0 And (KeyAscii > 47 And KeyAscii < 58) Then
If Len(Mid(txtAmount.Text, (InStr(1, txtAmount.Text, ".") + 1))) >= 2 _
And txtAmount.SelStart >= InStr(1, txtAmount.Text, ".") Then KeyAscii = 0
Else
If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 8 Or KeyAscii = 46 Then
' Admit that key
Else
KeyAscii = 0
End If
End If
End Sub

KeyAscii

Views 3,370

Downloads 1,446

CodeID
DB ID