I am looking to iterate through an array and change the visibility of a userform checkbox based on the array index value i.e. if the checkbox caption is equal to the array index value, then the checkbox visibility is set accordingly. By defualt, the visibility of checkboxes is true, and I want to hide checkboxes whose caption value do not appear in an array. The problem I am having is that all the checkboxes are visible despite the conditions set. I have checked the values of all iteration variables and the array values, and all seems to be ok. I am concerned whether I am initialising the userform incorrectly or in the wrong location? Any help will be greatly appreciated. {
With XrayFile
'populates array with values in variable worksheet range
Dim Xrayrange As Integer
lastpos = Sheets(Ship).Cells(Rows.Count, "A").End(xlUp).Row - 1
Xrayrange = lastpos - 6
'create array with variable dimensions based on worksheet range
ReDim X_ray_pos(Xrayrange) As String
Dim j As Integer
'iterate through worksheet range and set array index to cell value
For j = LBound(X_ray_pos) To UBound(X_ray_pos)
X_ray_pos(j) = Sheets(Ship).Range("A7").Offset(j).Value2
Next j
'userform1 is where the checkboxes are located. I chose to initialize the userform here thinking that it would matter for the iteration and change of the default state of the checkboxes
userfrom1.Show
userform1.Hide
Dim num As Variant
Dim i As Long
'iterates through checkboxes (named "CB1", "CB2" etc) and compares checkbox caption to array index value
For Each num In X_ray_pos
For i = 0 To 55
If Reject_list.Controls("CB" & i).Caption = num Then
Reject_list.Controls("CB" & i).Value = False
Else
Reject_list.Controls("CB" & i).Value = True
End If
Next i
Next num}
Aucun commentaire:
Enregistrer un commentaire