Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Changing the font for part of an axis label, not the whole label. | Charts and Charting in Excel | |||
Show Results in TextBoxes, ONLY if All TextBoxes have Data in them | Excel Programming | |||
How to rezize data label box in pie charts (label wraps to two lin | Charts and Charting in Excel | |||
How can I change the label of the total fields in a pivot table? | Excel Discussion (Misc queries) | |||
add up and calculate textboxes into a label | Excel Programming |