mardi 28 avril 2020

Create an ActiveX checkbox that check and unchecks all other checkboxes

I've got a sheet with a lot of checkboxes. The first one has the caption Check All and when you click it, all checkboxes should be checked. That works fine, but I also want to uncheck all the checkboxes by unchecking it and I can't get that to work. I get the error 1004. This is the code I'm trying:

Private Sub CheckBox1_Click()
On Error GoTo finished
For i = 2 To 200
    If ActiveSheet.OLEObjects("CheckBox1").Object.Value = True Then ' <- this line gives the 1004 error
        ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = False
    Else
        ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = True
    End If
Next i
Exit Sub
finished:
End Sub



Aucun commentaire:

Enregistrer un commentaire