Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perform a sum on textbox values

Status
Not open for further replies.

vestax22

Programmer
Jun 18, 2003
139
CA
Hi, I'm creating an Excel application which calls upon a userform. On this form there are four textboxes. Three of the four textboxes will contain manual inputs. The fourth textbox should contain the sum of the other three textboxes. On the afterupdate event of my three textboxes i do a sum of the three textboxes and modify the value of the fourth textbox. Excel VBA seems to think the vales inside the textboxes are text by default so I cannot do a sum. Is there a way to do this. Thx in advance


 
Hi,

Something like this would work...
Code:
    Dim nValue1 As Single, nValue2 As Single
    With ActiveSheet
        nValue1 = TextBox1.Text
        nValue2 = TextBox2.Text
        TextBox3.Text = nValue1 + nValue2
    End With


Skip,
Skip@TheOfficeExperts.com
 
Yes, thx for the reply


Is this the only way because I would like to avoid using variables.


Thx
 
Hey skip

I tried that already and it doesn't work. I did it with CInt. Any other suggestions?

Thx
 
Try this for the AfterUpdate events:
Code:
if isnumeric(textbox1) and isnumeric(textbox2) and _
   isnumeric(textbox3) Then
    TextBox4 = Val(TextBox1) + Val(TextBox2) + Val(TextBox3)
Else
    TextBox4 = "Error!"
End If


Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top