Option Explicit
Private Sub Worksheet_Activate()
Dim TE(), TS(1 To 5000, 1 To 4), LE&, LS&, PasFait As Boolean, NbLig&, TOn As Double
TE = Feuil1.UsedRange.Value
For LE = 2 To UBound(TE, 1)
If TE(LE, 1) <> "" Then
If LS > 0 Then TS(LS, 4) = NbLig
LS = LS + 1: TS(LS, 1) = TE(LE, 1)
PasFait = True: NbLig = 0: TOn = 0
Else
If PasFait Then
If Val(TE(LE, 2)) <> 0 Then TOn = Val(TE(LE, 2))
If TE(LE, 3) <> "" And TE(LE, 4) = "non" Then TS(LS, 2) = Val(TE(LE, 3)): TS(LS, 3) = Val(TE(LE, 3)) - TOn: PasFait = False
End If
NbLig = NbLig + 1: End If: Next LE
TS(LS, 4) = NbLig
[A2:D5001].Value = TS
End Sub