Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default add total from 6 textboxes and put in label

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default add total from 6 textboxes and put in label

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default add total from 6 textboxes and put in label

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default add total from 6 textboxes and put in label

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the font for part of an axis label, not the whole label. amy45 Charts and Charting in Excel 2 April 5th 23 01:11 PM
Show Results in TextBoxes, ONLY if All TextBoxes have Data in them RyanH Excel Programming 3 November 19th 07 03:30 PM
How to rezize data label box in pie charts (label wraps to two lin rolliedogg Charts and Charting in Excel 1 October 18th 06 08:17 PM
How can I change the label of the total fields in a pivot table? GG Excel Discussion (Misc queries) 1 July 2nd 06 02:26 PM
add up and calculate textboxes into a label Peter[_55_] Excel Programming 3 September 16th 05 05:49 AM


All times are GMT +1. The time now is 05:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"