cpounds217
03-22-2018, 11:23 AM
Hi All!
So this is been an interesting little bit of trial and error...more error than anything.
I have a userform, as seen below, which has 50 checkboxes. During the initialize event, these checkboxes are made visible, or not, based on whether a cell in a sheet is populated, and then their captions are changed to show that cell's value. The returned userform should have "x" number of checkboxes, with the appropriate captions. The problem is the loop seems to skip any Checkbox that is an even value.
Naming references: I have left checkboxes all as their "default" name for the sake of the loop coding, so they are CheckBox1, CheckBox2, etc...
I have two images attached, one is the coding version of the userform, and the other is the end-user (currently) userform.
Private Sub UserForm_Initialize()
MEFLabel.Caption = ActiveCell.Value
Call Checkbox_Start
End Sub
Private Function Checkbox_Start()
Dim i As Long
Dim y As Long
Dim ctl As Control
i = 1
y = 2
For i = 1 To 50
Set ctl = Me.HazardsFrm.Controls("CheckBox" & i)
If wsHazRanking.Range("B" & y).Value <> "" Then
ctl.Visible = True
ctl.Caption = wsHazRanking.Range("B" & y).Value
Else
ctl.Visible = False
End If
i = i + 1
y = y + 1
Next
End Function
21895
21896
The second image should either have all the even CheckBoxes not visible, or have captions different. There are currently ten "hazards" to populate the checkboxes, so ideally there would be five per side, and the rest would be invisible.
Any help is greatly appreciated. And as always, I CANNOT upload the spreadsheets, the images are as much as I can do.
Thank you!
So this is been an interesting little bit of trial and error...more error than anything.
I have a userform, as seen below, which has 50 checkboxes. During the initialize event, these checkboxes are made visible, or not, based on whether a cell in a sheet is populated, and then their captions are changed to show that cell's value. The returned userform should have "x" number of checkboxes, with the appropriate captions. The problem is the loop seems to skip any Checkbox that is an even value.
Naming references: I have left checkboxes all as their "default" name for the sake of the loop coding, so they are CheckBox1, CheckBox2, etc...
I have two images attached, one is the coding version of the userform, and the other is the end-user (currently) userform.
Private Sub UserForm_Initialize()
MEFLabel.Caption = ActiveCell.Value
Call Checkbox_Start
End Sub
Private Function Checkbox_Start()
Dim i As Long
Dim y As Long
Dim ctl As Control
i = 1
y = 2
For i = 1 To 50
Set ctl = Me.HazardsFrm.Controls("CheckBox" & i)
If wsHazRanking.Range("B" & y).Value <> "" Then
ctl.Visible = True
ctl.Caption = wsHazRanking.Range("B" & y).Value
Else
ctl.Visible = False
End If
i = i + 1
y = y + 1
Next
End Function
21895
21896
The second image should either have all the even CheckBoxes not visible, or have captions different. There are currently ten "hazards" to populate the checkboxes, so ideally there would be five per side, and the rest would be invisible.
Any help is greatly appreciated. And as always, I CANNOT upload the spreadsheets, the images are as much as I can do.
Thank you!