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
| Private Sub FaireSomme(NbrLignesRemplies)
If (Calendar1.Value <= Calendar2.Value) Then
deb = Calendar1.Value
fin = Calendar2.Value
For i = 2 To NbrLignesRemplies 'on commence par i=2 car la ligne 1 correspond aux titres des colonnes
If (Not IsEmpty(Feuil1.Cells(i, 1)) And (Feuil1.Cells(i, 1) >= deb) And (Feuil1.Cells(i,1) <= fin)) Then
'on fait la somme des valeurs dans "Total"
Total = Total + Feuil1.Cells(i, 5) 'Total est initialisé à 0 avant de rentrer dans la fonction
LabelValeur.Caption = " Total : " & Total
LabelValeur.Visible = True
LabelCondition.Caption = "OK"
Else
LabelValeur.Visible = False
CommandButtonOK.Visible = True
LabelCondition.Caption = "condition non acceptée"
End If
Next i
Else
LabelCondition.Caption = "Erreur : Vérifiez que la date de début précède la date de fin."
LabelCondition.Visible = True
LabelValeur.Visible = False
CommandButtonOK.Visible = True
End If
LabelCondition.Visible = True
End Sub |
Partager