PDA

View Full Version : Summing textboxes



streub
11-22-2013, 03:09 PM
I have 31 textboxes on a userform. Each box represents a budget figure for that day. The textboxes are "t1" through "t31" and the sum is to appear in "tt".

This is what is NOT working for me.



Private Sub t31_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim x As Long, lCount As Long
For x = 1 To 31
If Me.Controls("t" & x) = "*" Then lCount = lCount + Val(Me.Controls("t" & x).Text)
Next x
tt = lCount
End Sub

mancubus
11-22-2013, 04:05 PM
below worked for me:



For x = 1 To 31
lCount = lCount + Val(Controls("t" & x))
Next x
tt = lCount




i think you want to test if any textbox is empty.

Val function returns 0 if the string does not contain a numeric value.



Sub test()
MsgBox Val("6th ave")
MsgBox Val(6)
MsgBox Val("")
MsgBox Val(" ")
End Sub

streub
11-22-2013, 05:01 PM
Most excellent!

I love this:"... Make my enemy brave and strong, so that if defeated, I will not be ashamed..." Big Lodge Pole, Blackfeet

Blackfoot is in my heritage.

mancubus
11-23-2013, 02:55 AM
you are welcome. :)



"Give wisdom and understanding to my leaders.
Protect my warriors and bring them back safe.
Give to the young, love and contentment.
Give health and long life to my old people so that they may remain with us for a long time.
Make my enemy brave and strong, so that if defeated, I will not be ashamed.
And give me wisdom so that I may have kindness for all.
And let me live each day, so when day is done, my prayer will not have been in vain."