Calculate formatted Textbox

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have 5 textboxes that are used to display values. The textboxes are formatted such that a negative number is formatted in parenthesis, for example, -0.25, (.25). Finally, I have a sixth textbox that sums the previous five values in the textboxes. The problem is that values being formatted in parenthesis is now treated as a negative in the calculation. How to calculate the values in parenthesis as negative number?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
What is the code for the textbox that is formatted to show negative numbers as (100)?
 
Upvote 0
My code looks something like this:

Textbox6.value = Format(val(textbox1.value) + val(textbox2.value)...,"0.000;(0.000)")

Thus, textbox1...textbox5 are Format(val(textbox1.value),"0.000;(0.000)"). So, each Textbox can have a positive or negative value. I want Textbox6 to have the sum of all the previous textboxes. The result can be negative, i.e., (0.30), or positive, 50.2.
 
Upvote 0
Nevermind that. Is it possible to post your whole code?
 
Last edited:
Upvote 0
Code:
Public Sub CalcAdjust()
    lblAdjuster.Caption = " " & Format(val(lblAutoPay.Caption) + WMGAdjustor + val(lblTerm.Caption) + val(lblOccupancy.Caption), "0.00;(0.00)")
End Sub
 
Upvote 0
How about trying something like this:

Code:
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox6.Value = Format(Val(TextBox1.Value) + Val(TextBox2.Value) + Val(TextBox3.Value) + Val(TextBox4.Value) + Val(TextBox5.Value), "0.000;(0.000)")
TextBox1.Value = Format(TextBox1.Value, "0.00;(0.00)")
TextBox2.Value = Format(TextBox2.Value, "0.00;(0.00)")
TextBox3.Value = Format(TextBox3.Value, "0.00;(0.00)")
TextBox4.Value = Format(TextBox4.Value, "0.00;(0.00)")
TextBox5.Value = Format(TextBox5.Value, "0.00;(0.00)")
End Sub

That way when you have entered say -2 in textbox1 when you are done entering all your values it will change -2 to (2.00) but still calculate correctly. Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,865
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top