Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default 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!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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!!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding up number of people present at certain times bamboozled Excel Worksheet Functions 4 September 18th 07 09:02 AM
Why is my sum total a couple pennies off from what it should be? Chrissy[_2_] Excel Discussion (Misc queries) 2 March 2nd 07 05:42 AM
How can I add present month, as number, to an header in excel? Agnes _TASOT Excel Discussion (Misc queries) 1 December 21st 06 08:23 PM
How to count the number of cells highlighted using Conditional Formatting feature present in Format Menu of Excel??? divya Excel Programming 3 November 1st 06 12:47 PM
How can I count number of sheets present in a workbook? Imran Excel Discussion (Misc queries) 1 October 6th 06 11:06 AM


All times are GMT +1. The time now is 06:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"