Forum

How to set checkbox...
 
Notifications
Clear all

How to set checkbox array

3 Posts
3 Users
0 Reactions
197 Views
(@yossi321)
Posts: 1
New Member
Topic starter
 

I have some activex checkboxs
checkbox1, checkbox2 and so on
How can I set array variable for them in vba?

I tried

Dim TBarray(1 To 10) As CheckBox

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

 
Posted : 07/08/2023 7:23 pm
(@catalinb)
Posts: 1937
Member Admin
 

Try:

Dim TBarray(1 To 10) As OLEObject
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

 
Posted : 12/08/2023 1:50 am
(@debaser)
Posts: 837
Member Moderator
 

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.

 
Posted : 15/08/2023 3:30 am
Share: