Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Long, i As Long
If Application.Intersect(Target, Columns('B:C')) Is Nothing Then Exit Sub
R = Target.Row
If R = 1 Or R = 2 Then Exit Sub
On Error GoTo Out
If R = 3 Then
Cells(R, 4) = Cells(R, 2) - Cells(R, 3)
Else
Cells(R, 4) = Cells(R - 1, 4) + Cells(R, 2) - Cells(R, 3)
End If
On Error GoTo 0
If Not R = Range('D65536').End(xlUp).Row Then
MsgBox 'Changement sur entrée antérieure, Recalcul Complet, veuillez Patienter'
For i = R + 1 To Range('D65536').End(xlUp).Row
Cells(i, 4) = Cells(i - 1, 4) + Cells(i, 2) - Cells(i, 3)
Next
End If
Exit Sub
Out:
If Err = 13 Then
Target = ''
Else
MsgBox 'Erreur non gérée ' & Err.Number & ' ' & Err.Description
End If
End Sub