View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Charles Maxson Charles Maxson is offline
external usenet poster
 
Posts: 24
Default Userform and Text Box

Jamie,

Using the Change events from the textboxes, you can call a routine that adds
up specific textboxes and plop that value in another. Here's an example
where code behind the form totals up textboxes 2,3 & 4 and displays them in
TextBox1. It assumes that the controls that you want summed up (2,3,4 in
this case) have a Tag property that equals the word "sum". To add more
controls, simply add them and give them a "sum" tag and add the ReCalc
routine to their Change event.

Sub ReCalc()
Dim ctl As Control
Dim dValue As Double

For Each ctl In Me.Controls
If ctl.Tag = "sum" Then
dValue = dValue + Val(ctl.Value)
End If
Next

TextBox1.Value = dValue

End Sub

Private Sub TextBox2_Change()
ReCalc
End Sub

Private Sub TextBox3_Change()
ReCalc
End Sub

Private Sub TextBox4_Change()
ReCalc
End Sub



--
Charles
www.officezealot.com


"Jamie" wrote in message
...
I have a userform with quite a few text boxes where
numerical values are entered (with decimal points). I want
to use one of the text boxes on the same userform to show
a running total of the values entered in other text boxes.
Is there a way of doing this? Thanks is advance.