ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help adding formatted textboxes (https://www.excelbanter.com/excel-programming/360512-need-help-adding-formatted-textboxes.html)

Terry K

Need help adding formatted textboxes
 
Hello all,
I am pretty much a rookie but thanks to all of the great resources in
this site I am progessing even if slowly. I am using excel 2003 SP2.
I would like to have three formatted text boxes add. Here is my current
code:

If IsNumeric(txtadmingross.Text) Then
txtadmingross.Text = Format(txtadmingross.Text, "#,##0")
txtTotalGross = Format(Val(txtGross.Text) + Val(txtFI.Text) _
+ Val(txtadmingross.Text), "$#,##0")
Else
MsgBox "Entry must be numeric", vbInformation, "Invalid Entry"
txtadmingross.Text = ""
End If

My problem is that I would like to display the text in txtadmingross
formatted as "$#,##0" as soon as I make this change it no longer adds.
Is this possible? Can I have each of the three text boxes formatted as
currency, at the time of entry (as well as the result) and still have
them add? What am I missing?
Any suggestions would be greatly appreciated.
Terry


Norman Jones

Need help adding formatted textboxes
 
Hi Terry,

Try:

If IsNumeric(txtadmingross.Text) Then
txtadmingross.Text = Format(txtadmingross.Text, "$#,##0")
txtTotalGross = Format(CDbl(txtGross.Text) + CDbl(txtFI.Text) _
+ CDbl(txtadmingross.Text), "$#,##0")
Else
MsgBox "Entry must be numeric", vbInformation, "Invalid Entry"
txtadmingross.Text = ""
End If


---
Regards,
Norman


"Terry K" wrote in message
ups.com...
Hello all,
I am pretty much a rookie but thanks to all of the great resources in
this site I am progessing even if slowly. I am using excel 2003 SP2.
I would like to have three formatted text boxes add. Here is my current
code:

If IsNumeric(txtadmingross.Text) Then
txtadmingross.Text = Format(txtadmingross.Text, "#,##0")
txtTotalGross = Format(Val(txtGross.Text) + Val(txtFI.Text) _
+ Val(txtadmingross.Text), "$#,##0")
Else
MsgBox "Entry must be numeric", vbInformation, "Invalid Entry"
txtadmingross.Text = ""
End If

My problem is that I would like to display the text in txtadmingross
formatted as "$#,##0" as soon as I make this change it no longer adds.
Is this possible? Can I have each of the three text boxes formatted as
currency, at the time of entry (as well as the result) and still have
them add? What am I missing?
Any suggestions would be greatly appreciated.
Terry




Terry K

Need help adding formatted textboxes
 
Thank you very much Norman. That does work but it does lead to another
question - Originally in my initalize statement I had all text boxes =
empty (used also for a cmd button to clear all text boxes). In this
state when I entered my first value I would get run time error 13, type
mismatch, on the two text boxes that were empty. I changed the
initalize statement to set these 3 to zero and it works great. Is there
anyway around this? Just in terms of appearance - It might look better
if all text boxes were blank rather than some being blank and others
having zeros.
Thanks Terry


Norman Jones

Need help adding formatted textboxes
 
Hi Terry,

One way, perhaps:

Dim v1, v2, v3, v4

v1 = Replace(txtadmingross.Text, "$", "")
v2 = Replace(txtGross.Text, "$", "")
v3 = Replace(txtF1.Text, "$", "")

If IsNumeric(v1) Then
v1 = CDbl(v1)
Else
v1 = 0
End If

If IsNumeric(v2) Then
v2 = CDbl(v2)
Else
v2 = 0
End If

If IsNumeric(v3) Then
v3 = CDbl(v3)
Else
v3 = 0
End If

txtadmingross.Text = Format(txtadmingross.Text, "$#,##0")
txtTotalGross.Text = Format(v1 + v2 + v3, "$#,##0")


---
Regards,
Norman


"Terry K" wrote in message
oups.com...
Thank you very much Norman. That does work but it does lead to another
question - Originally in my initalize statement I had all text boxes =
empty (used also for a cmd button to clear all text boxes). In this
state when I entered my first value I would get run time error 13, type
mismatch, on the two text boxes that were empty. I changed the
initalize statement to set these 3 to zero and it works great. Is there
anyway around this? Just in terms of appearance - It might look better
if all text boxes were blank rather than some being blank and others
having zeros.
Thanks Terry




Terry K

Need help adding formatted textboxes
 
Perfect then. Thank you very much. I will give that a try this
afternoon.
Thank you very much for your help.
Terry



All times are GMT +1. The time now is 03:05 AM.

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