Sum on textbox value on userform reloaded

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,573
How do I add a continuous range say 5 to 16? Instead of adding 5 and 16 as below?

I tried "To" and ":" for the "," but didn't work out.

Code:
Sub oSum()
Dim n&, s As Double, TbRay As Variant 

TbRay = Array(5, 16)
For n  = 0 To UBound(TbRay)
       s = s + Val (UserForm1.Controls("TextBox" & TbRay(n)).Object.Value)
Next
UserForm1.TextBox17.Value = s 
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,213
Office Version
365
Platform
Windows
Try
Code:
Sub oSum()
Dim n&, s As Double

For n = 5 To 16
       s = s + Val(userform1.Controls("TextBox" & n).Object.Value)
Next
userform1.TextBox17.Value = s
End Sub
 

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,573
Try
Code:
Sub oSum()
Dim n&, s As Double

For n = 5 To 16
       s = s + Val(userform1.Controls("TextBox" & n).Object.Value)
Next
userform1.TextBox17.Value = s
End Sub

Perfectly on point.

Have a wonderful time
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,213
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,077,784
Messages
5,336,329
Members
399,076
Latest member
vullistax

Some videos you may like

This Week's Hot Topics

Top