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 34 35 36 37 38 39 40 41 42 43
|
Public Sub dureeIncident()
Dim dIncident As Date, hIncident As Date
Dim intNbJours As Integer, strJours As String
Dim dCloture As Date, hCloture As Date
Dim hOuverture As Date, hFermeture As Date, hDay As Date
Cells(2, 1).Select
Do While Not IsEmpty(ActiveCell.Value)
dIncident = Cells(ActiveCell.Row, 1).Value
dCloture = Cells(ActiveCell.Row, 3).Value
hIncident = Format(dIncident, "hh:mm:ss")
hCloture = Format(dCloture, "hh:mm:ss")
hOuverture = Cells(2, 7).Value
hFermeture = Cells(2, 8).Value
hDay = Cells(2, 9).Value
intNbJours = dCloture - dIncident
If hIncident < hOuverture Then
Cells(ActiveCell.Row, 5).Value = Format(hOuverture - hIncident + hCloture - hFermeture, "hh:mm:ss")
ElseIf hIncident > hOuverture And hIncident < hFermeture Then
Cells(ActiveCell.Row, 5).Value = Format(hCloture - hFermeture, "hh:mm:ss")
ElseIf hIncident > hFermeture Then
If hIncident > hCloture Then
Cells(ActiveCell.Row, 5).Value = Format(hDay - Abs(hCloture - hIncident), "hh:mm:ss")
intNbJours = intNbJours - 1
Else
Cells(ActiveCell.Row, 5).Value = Format(hCloture - hIncident, "hh:mm:ss")
End If
End If
If intNbJours >= 2 Then
strJours = intNbJours & " jours et "
ElseIf intNbJours = 1 Then
strJours = intNbJours & " jour et "
Else
strJours = ""
End If
Cells(ActiveCell.Row, 5).Value = strJours & Format(Cells(ActiveCell.Row, 5).Value, "hh:mm:ss")
ActiveCell.Offset(1, 0).Select
Loop |
Partager