TextBox

danielalmada

New Member
Joined
Oct 21, 2002
Messages
2
Two questions:

1.- How do I add values inside two different textboxs? I need that value to appear on another textbox!!


2.- I need to add values inside textboxes, but it shouldn't add one of the values if the textbox is not enabled. How can I keep out of the adding on question #1 the not enabled textboxes?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
On 2002-10-22 11:49, danielalmada wrote:
Two questions:

1.- How do I add values inside two different textboxs? I need that value to appear on another textbox!!


2.- I need to add values inside textboxes, but it shouldn't add one of the values if the textbox is not enabled. How can I keep out of the adding on question #1 the not enabled textboxes?

Not sure I'm understanding. Do you want to add together the values contained inside of 2 different text boxes?

If so, you can try something like this:

Code:
Sub AddTogether()
    Sheet1.TextBox3 = Val(Sheet1.TextBox2) + Val(Sheet1.TextBox1)
End Sub

The Sheet1 is not necessary if you have the code in the Sheet1 class module. Or, you can replace Sheet1 with Worksheets("Sheet1")

If you don't want to add the values of TextBoxes that are not enabled, you could do this:

Code:
Sub AddTogether()
    Sheet1.TextBox3 = (Val(Sheet1.TextBox2) * Abs(Sheet1.TextBox2.Enabled)) _
                      + (Val(Sheet1.TextBox1) * Abs(Sheet1.TextBox1.Enabled))
End Sub

In VBA, False evaluates to 0 and True evaluates to -1. So the absolute value (Abs function) of those would be 0 and 1, respectively. So if the Enabled property of the textbox is False, then multiply its value by 0, but if it is Enabled, then multiply its value by 1 (the absolute value of -1). Make sense?

Let me know if that's not what you had in mind. Otherwise, I hope that helps. There are many other ways to do this, and knowing this board, people will offer their favorite ways also.

-Russell
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,058
Members
448,940
Latest member
mdusw

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