décocher toutes les cases à cocher d'une feuille

306255

XLDnaute Occasionnel
Bonjour,

Est-il possible de décocher toutes les cases à cocher d'une feuille en cliquant sur un bouton.

Merci d'avance
 

jpb388

XLDnaute Accro
Bonjour à tous
Code:
' contrôle formulaire
Sub decoche()
    Dim Ctl As Shape
    For Each Ctl In ActiveSheet.Shapes
        If Left(Ctl.Name, 9) = "Check Box" Then Ctl.ControlFormat.Value = xlOff
    Next Ctl
End Sub

Sub coche()
    Dim Ctl As Shape
    For Each Ctl In ActiveSheet.Shapes
        If Left(Ctl.Name, 9) = "Check Box" Then Ctl.ControlFormat.Value = xlOn
    Next Ctl
End Sub

' contrôle activeX
Sub decocheX()
    Dim Ctl As OLEObject
    For Each Ctl In ActiveSheet.OLEObjects
    If TypeOf Ctl.Object Is MSForms.CheckBox Then Ctl.Object = False
    Next Ctl
End Sub

Sub cocheX()
    Dim Ctl As OLEObject
    For Each Ctl In ActiveSheet.OLEObjects
    If TypeOf Ctl.Object Is MSForms.CheckBox Then Ctl.Object = True
    Next Ctl
End Sub
 

306255

XLDnaute Occasionnel
Bonjour à tous
Code:
' contrôle formulaire
Sub decoche()
    Dim Ctl As Shape
    For Each Ctl In ActiveSheet.Shapes
        If Left(Ctl.Name, 9) = "Check Box" Then Ctl.ControlFormat.Value = xlOff
    Next Ctl
End Sub

Sub coche()
    Dim Ctl As Shape
    For Each Ctl In ActiveSheet.Shapes
        If Left(Ctl.Name, 9) = "Check Box" Then Ctl.ControlFormat.Value = xlOn
    Next Ctl
End Sub

' contrôle activeX
Sub decocheX()
    Dim Ctl As OLEObject
    For Each Ctl In ActiveSheet.OLEObjects
    If TypeOf Ctl.Object Is MSForms.CheckBox Then Ctl.Object = False
    Next Ctl
End Sub

Sub cocheX()
    Dim Ctl As OLEObject
    For Each Ctl In ActiveSheet.OLEObjects
    If TypeOf Ctl.Object Is MSForms.CheckBox Then Ctl.Object = True
    Next Ctl
End Sub


Merci c'est impeccable pour moi

Merci encore
 

Staple1600

XLDnaute Barbatruc
Bonjour le fil, le forum

Une autre solution (où on utilise la même macro pour cocher ou décocher)

VB:
Sub test_I()
'coche tous les types de CheckBox
Application.ScreenUpdating = False
Cochez True
End Sub
Sub test_II()
'décoche tous les types de CheckBox
Application.ScreenUpdating = False
Cochez False
End Sub

Private Sub Cochez(statut As Boolean)
Dim c As Object
With ActiveSheet
    .CheckBoxes.Value = statut
    For Each c In .OLEObjects
    If TypeName(c.Object) = "CheckBox" Then c.Object.Value = statut
    Next c
End With
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 194
Messages
2 086 064
Membres
103 110
dernier inscrit
Privé