MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Adding values with code


Posted by Ian on September 14, 2001 9:35 AM

hi all

I have a simple user form that has 30 check boxes
if they are ticked it's worth 1 pt

i'm looking for the quickest way to add all the checkboxes values

i could use

Dim result as long

Result = 0
if checkbox1.value = true then
Result = Result + 1

etc.

how could i write it so it says something like

for _every time a box is true add 1

Any help

the reason i ask is the checkboxes may increase to 50 or 60

cheers ian


Posted by Juan Pablo on September 14, 2001 9:48 AM

Try this one... works for me at least...

Juan Pablo

Sub CountCB()
Dim CB As MSForms.CheckBox, i As Long
i = 0
On Error Resume Next
For Each CB In UserForm1.Controls
If CB Then i = i + 1
Next CB
MsgBox i
End Sub