| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 
 | '--------------------------------------
'dans un module de classe nommé "Classe1"
'
Option Explicit
 
Public WithEvents ChBox As MSForms.CheckBox
 
 
Private Sub ChBox_Click()
    Dim x As Long
    Dim Ws As Worksheet
    Dim PlageSomme As Range
    Set Ws = ActiveSheet
 
    'Vérifie si un checkbox placé sur la premiere ligne
    'est utilisé:
    If ChBox.TopLeftCell.Row = 1 Then
 
        'Recupere la derniere ligne du tableau
        x = Ws.Cells(1, 1).End(xlDown).Row
 
        'Si le checkbox est coché :
        If ChBox.Value Then
 
            'Definit la plage de sellules pour la somme
            Set PlageSomme = Ws.Range(Ws.Cells(2, ChBox.TopLeftCell.Column), _
                Ws.Cells(x - 1, ChBox.TopLeftCell.Column))
 
            'Applique la formule dans la derniere cellule de la
            'colonne.
            Ws.Cells(x, ChBox.TopLeftCell.Column).Formula = _
                "=SUM(" & PlageSomme.Address & ")"
        Else
            'Sinon indique 0 dans la cellule
            Ws.Cells(x, ChBox.TopLeftCell.Column) = 0
        End If
    Else
 
        x = Ws.Cells(1, 1).End(xlToRight).Column
 
        If ChBox.Value Then
 
            Set PlageSomme = Ws.Range(Ws.Cells(ChBox.TopLeftCell.Row, 2), _
                Ws.Cells(ChBox.TopLeftCell.Row, x - 1))
 
            Ws.Cells(ChBox.TopLeftCell.Row, x).Formula = _
                "=SUM(" & PlageSomme.Address & ")"
        Else
            Ws.Cells(ChBox.TopLeftCell.Row, x) = 0
        End If
    End If
End Sub
 
'-------------------------------------- | 
Partager