Multiple textboxes sum value!

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Code:
TextBox81.Value = Val(TextBox21) + Val(TextBox22) + Val(TextBox23)........+ Val(TextBox40)

Good Day,
Is there any easy way to get the total value with the captioned sample code above?
Many Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Use the following code within a Command Button Click Event or a Lost Focus Event procedure of a control:

Code:
dim j as integer, amount as double

amount=0
for j=21 to 40
   amount = amount + val("TextBox" & j)
next
[TextBox81] = amount
 
Upvote 0
Use the following code within a Command Button Click Event or a Lost Focus Event procedure of a control:

Code:
dim j as integer, amount as double
 
amount=0
for j=21 to 40
   amount = amount + val("TextBox" & j)
next
[TextBox81] = amount


Thanks for ur reply,
But im still having the result of "0" value.
Cheers
 
Upvote 0
Give this a spin...

Code:
Dim Total2140 As Long: Total2140 = 0
For ctrlidx = 0 To Me.Controls.Count - 1
    If TypeOf Me.Controls(ctrlidx) Is MSForms.TextBox Then
        Select Case Right(Controls(ctrlidx).Name, 2)
            Case 21 To 40
                Total2140 = Total2140 + Controls(ctrlidx).Value
            Case Else
        End Select
    End If
Next ctrlidx
TextBox81.Value = Total2140
 
Upvote 0
Give this a spin...

Code:
Dim Total2140 As Long: Total2140 = 0
For ctrlidx = 0 To Me.Controls.Count - 1
    If TypeOf Me.Controls(ctrlidx) Is MSForms.TextBox Then
        Select Case Right(Controls(ctrlidx).Name, 2)
            Case 21 To 40
                [COLOR=red]Total2140 = Total2140 + Controls(ctrlidx).Value[/COLOR]
            Case Else
        End Select
    End If
Next ctrlidx
TextBox81.Value = Total2140

Run time error '13':
Type mismatch
Cheers
 
Upvote 0
You have non-numerics in the textboxes then ...

Total2140 = Total2140 + Val(Controls(ctrlidx))
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top