ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add the $.00 pennies if no value is present after the whole number? (https://www.excelbanter.com/excel-programming/384008-add-%24-00-pennies-if-no-value-present-after-whole-number.html)

[email protected]

Add the $.00 pennies if no value is present after the whole number?
 
Hey all!

The idea is the following...

A person enters a value in to a textbox. Based on the valued entered
it may or may not have change... this is simply for uniformity in the
database. I'd like the following to happen...

End User types "$9.99" into textbox - nothing happens as it does have
a value after the period.

End User Types "$9" into textbox on exit the text box adds the ".00"
so it comes out to be "$9.00"

Any help is greatly appreciated!!


NickHK

Add the $.00 pennies if no value is present after the whole number?
 
In a suitable event use
TextBox1.Value=Format(TextBox1.Value,"#0.00")

NickHK

wrote in message
ups.com...
Hey all!

The idea is the following...

A person enters a value in to a textbox. Based on the valued entered
it may or may not have change... this is simply for uniformity in the
database. I'd like the following to happen...

End User types "$9.99" into textbox - nothing happens as it does have
a value after the period.

End User Types "$9" into textbox on exit the text box adds the ".00"
so it comes out to be "$9.00"

Any help is greatly appreciated!!




Chip Pearson

Add the $.00 pennies if no value is present after the whole number?
 
Try something like the following. When focus moves away from the text box to
another control, the text in the text box will be formatted with two decimal
places. The KeyPress event prevents the user from inputting alpha
characters. Only 0-9, '.', and '-' are allowed.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If Len(.Text) = 0 Then
.Text = "0.00"
Else
.Text = Format(.Text, "#,##0.00")
End If
End With
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, Me.TextBox1.Text, "-") 0 Or Me.TextBox1.SelStart 0
Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.TextBox1.Text, ".") 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)




wrote in message
ups.com...
Hey all!

The idea is the following...

A person enters a value in to a textbox. Based on the valued entered
it may or may not have change... this is simply for uniformity in the
database. I'd like the following to happen...

End User types "$9.99" into textbox - nothing happens as it does have
a value after the period.

End User Types "$9" into textbox on exit the text box adds the ".00"
so it comes out to be "$9.00"

Any help is greatly appreciated!!





All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com