add total from 6 textboxes and put in label
will give that a try and let u know. in the meanwhile i started thinking if
i shouldnt rather have only one textbox and a combobox.
the textbox the can enter the amount and the combo box will give the cashier
name.
and let it all add to a cell on sheet1 depending on the name. ie. anna colum
a and mari colum b and john colum c
and have the lable go and get the total from there.
will let u know
thanx
"Matthew Pfluger" wrote:
The best solution here is to rename your textboxes with a little prefix like
this:
"grp1TextBoxName"
Then you can run 1 loop that adds up textbox values based on that prefix:
Sub Example()
' Create variables
Dim dSum1 As Double
Dim dSum2 As Double
Dim dSum3 As Double
Dim ctrl As MSForms.Control
' Loop through controls looking for text boxes
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
If InStr(ctrl.Name, "grp1") < 0 Then
' Add to group 1 total
' Remove first letter from text box value
dSum1 = dSum1 + Right(ctrl.Text, Len(ctrl.Text) - 1)
ElseIf InStr(ctrl.Name, "grp2") < 0 Then
' Add to group 2 total
' Remove first letter from text box value
dSum2 = dSum2 + Right(ctrl.Text, Len(ctrl.Text) - 1)
ElseIf InStr(ctrl.Name, "grp3") < 0 Then
' Add to group 2 total
' Remove first letter from text box value
dSum3 = dSum3 + Right(ctrl.Text, Len(ctrl.Text) - 1)
End If
End If
Next ctrl
' Copy totals to labels
With Me
.label1.Value = dSum1
.label2.Value = dSum2
.label3.Value = dSum3
End With
End Sub
The code finds all textboxes, checks their name for either "grp1", "grp2",
or "grp3", and then adds up totals based on that naming convention.
Hope this helps,
Matthew Pfluger
"pswanie" wrote:
i got about 20 textboxes and need one set of 6 to sumtotal to label1
another 5 sumtotal to label2
and 3 to sumtotal to label3
"Matthew Pfluger" wrote:
Hello,
Try this:
Sub Example()
' Create variables
Dim dRunningTotal As Double
Dim ctrl As MSForms.ctrlontrol
' Loop through controls looking for text boxes
For Each ctrl In Me.ctrlontrols
If TypeOf ctrl Is MSForms.TextBox Then
' Remove first letter from text box value
dRunningTotal = dRunningTotal + Right(ctrl.Text, Len(ctrl.Text)
- 1)
End If
Next ctrl
' Copy total to label
Me.label24.Value = dRunningTotal
End Sub
HTH,
Matthew Pfluger
"pswanie" wrote:
i got 6 textboxes where users enter amounts. i need the total from those to
display in label24 userform1
would it be posible to default the amount enterd in a text box with the
prefix "R" and "." to seperate sents? we use amounts like R1125.80
|