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