Function CalculMarieL_V2()
Dim Lig1 As Long, Lig2 As Long, D1 As Long, D2 As Long, E1 As Long, E2 As Long
Dim i As Long, F1 As Long, G1 As Long
Application.Volatile
Lig1 = Application.ThisCell.Row 'ligne de la cellule selectionnée)
If Cells(Lig1, 1) <> "" And Cells(Lig1, 3) = "" Then
CalculMarieL_V2 = ""
Exit Function
End If
'recherche ligne précédente
For i = Lig1 - 1 To 5 Step -1 ' de la ligne courante à la dernière ligne utile
If Cells(i, 1) = Cells(Lig1, 1) And Cells(i, 3) = Cells(Lig1, 3) Then
Lig2 = i
Exit For
End If
Next
If Lig2 < 5 Then
CalculMarieL_V2 = ""
Exit Function
End If
D1 = Cells(Lig1, 4)
D2 = Cells(Lig2, 4)
E1 = Cells(Lig1, 5)
E2 = Cells(Lig2, 5)
F1 = Cells(Lig1, 6)
G1 = Cells(Lig1, 7)
If Cells(Lig1, 6) > 0 Then
'(D6+E6/60)-(D5+E5/60)+(F6+G6/60)-(D6+E6/60)
CalculMarieL_V2 = (F1 + G1 / 60) - (D2 + E2 / 60)
Else
'D6+E6/60)-(D5+E5/60)
CalculMarieL_V2 = (D1 + E1 / 60) - (D2 + E2 / 60)
End If
End Function