Question

J'ajoute beaucoup de cases à cocher à la feuille de calcul Excel à l'aide du code suivant:

With ActiveSheet.CheckBoxes.Add(rCell.Left, rCell.Top, rCell.Width, rCell.Height)
        .Interior.ColorIndex = xlNone
        .Caption = ""
End With

Maintenant, j'ai besoin d'un code qui analyse toutes les cases à cocher présentes dans la feuille et obtient leur valeur (true ou false) ainsi que la cellule dans laquelle elles se trouvent. Comment faire cela?

Merci ...

Était-ce utile?

La solution

Sub Add_CheckBoxes()

With ActiveSheet.CheckBoxes.Add(ActiveCell.Left, ActiveCell.Top, ActiveCell.Width, ActiveCell.Height)
    .Interior.ColorIndex = xlNone
    .Caption = ""
End With

For Each chk In ActiveSheet.CheckBoxes
    If chk Then MsgBox "Checked"
Next
End Sub

Autres conseils

Une fois que vous avez ajouté les cases à cocher, vous pouvez les parcourir comme suit:

Sub Checkbox_Test()

Dim chk As CheckBox
Dim cell As Range

For Each chk In ActiveSheet.CheckBoxes
    If chk.Value = Checked Then        '1 is true, but the constant
        Set cell = chk.TopLeftCell     ' "Checked" avoids "magic numbers".

        'do whatever with cell
        MsgBox cell.Address
    End If
Next chk

End Sub

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top