View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ken Johnson Ken Johnson is offline
external usenet poster
 
Posts: 1,073
Default How to Add 21 Textbox values to give the Sum ?


Corey wrote:
I have a userform with 21 textboxes i need to get the Sum of.
How can i code this?
The textboxes are not in indexed in order either.
They a
textbox6
textbox13
textbox22
textbox31
textbox39
textbox48
textbox56
textbox64
textbox72
textbox80
textbox88
textbox96
textbox104
textbox112
textbox120
textbox128
textbox136
textbox144
textbox152
textbox160
&
textbox168

I need to get the sum of ALL these textbox.values to be Calculated and
placed in textbox172 as the user fills in the values in the textboxes above.


Corey....


Hi Corey,

This code in the Change event of each of the 21 TextBoxes worked for
me. There could be an easier way though (I just don't know it:-))...

Private Sub TextBox6_Change()
Dim TxBx As Control
Const T As String = "TextBox"
Dim sngTxBx172Total As Single
For Each TxBx In UserForm1.Controls
Select Case TxBx.Name
Case T & 6, T & 13, T & 22, T & 31, T & 39, T & 48, T & 56, _
T & 64, T & 72, T & 80, T & 86, T & 104, T & 112, T & 120, _
T & 128, T & 136, T & 144, T & 152, T & 160, T & 168
If IsNumeric(TxBx.Text) Then
sngTxBx172Total = sngTxBx172Total + TxBx.Text
End If
End Select
Next TxBx
UserForm1.TextBox172.Text = sngTxBx172Total
End Sub

Ken Johnson