I've a excel vba code. I will have a userform and populate the userform with ckeckboxes during runtime getting the data from the spreadsheet. Now when i click the OK buton i need the code to check the values of the checkboxes. If any checkbox is checked then correspondingly it should peform some operations. I have used "IF" loop. But the code doesn't go to the IF loop. it just skips it. I have the sample code below.
Private Sub CommandButton1_Click()
lastrow = Range("D65536").End(xlUp).Row
For idx = 1 To latrow
If Me.Controls("cname" & idx).Value = True Then
'my code
End If
Next idx
UserForm1.Hide
End Sub
Private Sub selectall()
Dim idx As Integer
lastrow = Range("D65536").End(xlUp).Row - 4
Dim chk As Control
For idx = 1 To lastrow
Me.Controls("cname" & idx).Value = True
Next idx
End Sub
Private Sub userform_initialize()
Dim idx As Integer
lastrow = Range("D65536").End(xlUp).Row - 4
Dim EachLabel As Integer
Dim cCntrl As Control
Dim chk As Control
Dim tbindex As Integer
For idx = 1 To lastrow
Set chk1 = Frame1.Controls.Add("Forms.checkbox.1", "cname" & idx, True)
chk1.Caption = Cells(4 + idx, 4).Value
chk1.Visible = True
chk1.Left = 6
chk1.Top = 1 + idx * 17.5
chk1.Width = 100
chk1.Height = 15.75
Next
UserForm1.Frame1.ScrollBars = fmScrollBarsVertical
UserForm1.Frame1.ScrollHeight = 20 * lastrow
End Sub