PDA

View Full Version : Add values when checkbox is checked.



fadib
11-29-2007, 11:46 AM
Hi guys,
I have 10 textbox filled with values.
Next to each textbox I have a checkbox.
What I want to accomplish is to add all the textbox(s) for which the checkbox is checked.

I was able to do it for two check box, Now that i am going for more, I know that i need to create a loop. I know the logic of it, but I am having hard time to see where to put the variable.

Can anyone help me with that?

lucas
11-29-2007, 11:55 AM
On a sheet or on a userform?

fadib
11-29-2007, 01:25 PM
Userform.

lucas
11-29-2007, 01:32 PM
Can you post your workbook with the userform so we don't have to re-create your scenario?

fadib
11-29-2007, 02:58 PM
Here is what I have so far.


Private Sub CommandButton1_Click()

Dim i As Integer
Dim s As double
Dim a As double
s = 0
a = 0
For i = 1 To 10
If Me.Controls("Checkbox" & i).Value = True Then
a = Me.Controls("textbox" & i).Text
s = Val(s) + Val(a)
End If
Next i
Textbox11.text = val(s)

End Sub

fadib
11-29-2007, 03:20 PM
I figured it out. :thumb
Thank you though Lucas for your initiative in helping me.