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
| Private Sub Worksheet_Change(ByVal Target As Range)
Dim Nom_client As String, Montant_payé As Single, i As Integer, Acompte As Single, Solde As Currency
If Target.Count > 1 Then Exit Sub
If Not Application.Intersect(Target, Range("E10:E10000")) Is Nothing Then
Nom_client = Target.Offset(0, -2)
Montant_payé = Target
With Sheets("Saisie des ventes")
For i = 10 To .Range("D65000").End(xlUp).Row
If .Cells(i, 4) = Nom_client Then
Acompte = .Cells(i, 8)
Solde = .Cells(i, 9)
If Solde = 0 Then
GoTo Etiquette
Else
If Solde <= Montant_payé Then
.Cells(i, 8) = .Cells(i, 7)
Montant_payé = Montant_payé - Solde
Else
.Cells(i, 8) = Acompte + Montant_payé
Exit Sub ' car plus de fric à disposition
End If
End If
End If
Etiquette:
Next
End With
End If
If Montant_payé > 0 Then MsgBox "Il reste un montant excédentaire de " & Montant_payé
End Sub |
Partager