business_analyst
Board Regular
- Joined
- Jun 5, 2009
- Messages
- 99
Hello All,
I have textbox on a Userform that allows the user to enter a dollar amount from 1 to 99,999,999. I was trying to input code into the KeyPress event of the textbox to that while the user is entering an amount, the number is automatically split with commas. This is the code I have:
However, this code does not seem to be working properly. It actually inputs the comma after the fourth digit, for example: 12345 becomes 1,2345.
I am not sure why it is doing this, I have even tried changed around the format from: "#,###" to "##,###" to "###,###". All giving the same issue. Any help would be greatly appreciated.
I have textbox on a Userform that allows the user to enter a dollar amount from 1 to 99,999,999. I was trying to input code into the KeyPress event of the textbox to that while the user is entering an amount, the number is automatically split with commas. This is the code I have:
Code:
Private Sub txt_spend_Keypress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim num As String
If KeyAscii < 47 Or KeyAscii > 57 Then
KeyAscii = 0
End If
If txt_spend.Value <> "" Or txt_spend.Value <> 0 Then
txt_spend = Format(txt_spend, "#,###")
End If
End Sub
However, this code does not seem to be working properly. It actually inputs the comma after the fourth digit, for example: 12345 becomes 1,2345.
I am not sure why it is doing this, I have even tried changed around the format from: "#,###" to "##,###" to "###,###". All giving the same issue. Any help would be greatly appreciated.