Forms & Check boxes
Forms & Check boxes
(OP)
Hi all
Please suggest me in the following situation;
I need to make a form with check boxes on it. The number of check boxes on the form should vary according to the values in the range of cells. say 3 horizontal& 3 vertically down.
(Like a matrix on the form)
so can i add the number of checkboxes to the form and assign the properties to them?
your input will be always appreciated
Please suggest me in the following situation;
I need to make a form with check boxes on it. The number of check boxes on the form should vary according to the values in the range of cells. say 3 horizontal& 3 vertically down.
(Like a matrix on the form)
so can i add the number of checkboxes to the form and assign the properties to them?
your input will be always appreciated





RE: Forms & Check boxes
Here is a sample procedure that adds 3 checkboxes to a Userform. You will need to set the position properties for each created control, otherwise, they will be placed one on top of the other. Set additional properties as desired. You would call this from the Userform's Initialize event.
Sub AddCheckboxes()
Dim Ctrl As Control
Dim i As Integer
For i = 1 To 3
Set Ctrl = UserForm1.Controls.Add("Forms.Checkbox.1", "chk" & i, True)
With Ctrl
' Set checkbox properties here
End With
Next i
End Sub
HTH
Mike
RE: Forms & Check boxes
RE: Forms & Check boxes
Say I am having 100 checkboxes on the form ( which depends on the input). I name the check boxes as chk 1, chk 2, ....
At one point of time i need to check the value of checkbox true or false. i just tried with For loop checking all checkboxes? I don't know the format by which the all check boxes can be checked using For loop at once.
please help me in this regard
RE: Forms & Check boxes
The following procedure demonstrates a way to set the Value property of all your checkboxes. It takes one argument, ChkValue, which should be either 0 (unchecked) or 1 (checked). Note, this is at odds with the VBA Help, which indicates -1 for checked. I have found using -1 results in a checkmark with a gray background.
Sub SetCheckBoxes(ByVal ChkValue As Integer)
Dim Ctl As Control
For Each Ctl In UserForm1.Controls
If TypeName(Ctl) = "CheckBox" Then
Ctl.Value = ChkValue
End If
Next Ctl
End Sub
The use of the TypeName function restricts the code to taking action on checkboxes only, excluding other Userform controls (buttons, listboxes, textboxes, etc.).
Regards,
Mike
RE: Forms & Check boxes