I have some activex checkboxs
checkbox1, checkbox2 and so on
How can I set array variable for them in vba?
I tried
Dim i As Integer
For i = 1 To 6
If ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = True Then
MsgBox "Yes, it is true!"
Else:
MsgBox "No, it is not!"
Set TBarray(i) = ActiveSheet.OLEObjects("CheckBox" & i).Object 'here I get "Type mismatch"
Next i
Try:
Dim i As Integer
For i = 1 To 2
If ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = True Then
Else
Set TBarray(i) = ActiveSheet.OLEObjects("CheckBox" & i)
Debug.Print TBarray(i).Object.Value
End If
Next i
Excel has two types of checkbox and you are using activex ones (best avoided if you can) so you need:
Dim TBarray(1 To 10) As MSForms.CheckBox
You're also missing an End If before the Next i as Catalin showed.