ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform and Text Box (https://www.excelbanter.com/excel-programming/285289-userform-text-box.html)

Jamie[_6_]

Userform and Text Box
 
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.

Chris Leonard

Userform and Text Box
 
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.


Yes.

I can't remember the exact syntax but you have an event which is fired when
you exit a field in the event you want to put something like the following

totalfield.value = field1.value + field2.value .....

This will update your total field

HTH

Chris



David Thurston

User Form and text box
 
You first need to decide if a textbox is
appropriate...because it can allow for change in most
cases, so you may want to consider a label. Then, do you
want to have it calulate a total at the press of a button
on the form, or do it on value change of the test box, but
that can all be decided when you double click the box that
you want to have the total and then in the code, you can
choose the type of event that you want it to react on
(i.e. when you first get in to the code it will say
Private sub textbox1_change(). Then the rest is just a
formula like textbox1.value (or label1.caption) =
testbox2.value+textbox3.valeu...etc.

Hope this helps!
David
-----Original 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.
.


Charles Maxson

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.




BrianB

User Form and text box
 
Perhaps you just need a subroutine to do the update. This could then be
called by the On_Change event of the other text boxes.

eg. (pseudo code)

sub UpdateTotalBox()
Textbox10.Value = TextBox1.Value +Textbox2.Value .. etc.
End sub


---
Message posted from http://www.ExcelForum.com/


Jamie[_6_]

Userform and Text Box
 
Thanks for the reply.

When I run the codes, they put values from textboxes 2 and
3 side by side as text like 100200 instead of summing up
to 300. Any idea why. Thank you so much for your help.

-----Original Message-----
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.



.



All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com