looping and naming
Dim i As Long
Dim ctl As Control
Dim checkBoxArray
ReDim checkBoxArray(0 To 0)
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
ReDim Preserve checkBoxArray(0 To i)
checkBoxArray(i) = ctl.Value
i = i + 1
End If
Next ctl
--
HTH
Bob Phillips
(replace somewhere in email address with gmail if mailing direct)
"franzklammer" wrote in message
...
Hello! I have a user form in which I read values from text boxes and check
boxes. I then want to store these values in arrays. My code is now written
so
that I give values to the arrays directly. However it would be better to
loop
this process, a task that I seem to fail since I do not know how to handle
the reference to the text boxes and check boxes. My code:
checkBoxArray(0) = CheckBox1.Value
checkBoxArray(1) = CheckBox2.Value
checkBoxArray(2) = CheckBox3.Value
checkBoxArray(3) = CheckBox4.Value
I can replace the number refering to the place in the array with a
variable
but is it possible to handle the check boxes in the same manner i.e. refer
to
the by the usage of a variable? If so is there any function that counts
the
number of check boxes in a user form? I am greatful for any assistance
that
you can give me.
|