1 2 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
| Option Explicit
Private Sub ToggleButton1_Click()
With ToggleButton1
If .Value = True Then
.BackColor = RGB(255, 0, 0) 'Rouge
.Caption = "STOP"
ElseIf .Value = False Then
.Caption = "Calcul salaires"
.BackColor = RGB(0, 255, 0) 'Vert
'Mettre à zéro la somme
With Sheets("Feuil2")
.Range("I2").Value = 0
End With
End If
End With
End Sub
Private Sub Worksheet_Activate()
ToggleButton1.Value = False
If AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If
Range("I2").Value = 0
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As String
Application.ScreenUpdating = False
If Not Intersect(Target, [H2]) Is Nothing Then
' Critère du filtre
X = Range("H2").Value
' Zone du filtre
If AutoFilterMode = False Then
Range("A2:G2").AutoFilter
End If
' Filtre sur le critère
With Range("A2:G2")
.AutoFilter field:=6, Criteria1:="*" & X & "*"
End With
End If
Application.EnableEvents = False
If Not Intersect(Target, Range("G2:G" & Range("G65000").End(xlUp).Row)) Is Nothing _
And ToggleButton1.Value Then
If IsNumeric(Target.Value) Then [I2].Value = [I2].Value + Target.Value
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub |
Partager