[COLOR="DarkSlateGray"][B]Function TotHor(r As Range)
Application.Volatile
Dim oCel As Range, i&, x, y, t!
For Each oCel In r.Cells
If oCel.Value <> "OFF" And Not IsEmpty(oCel) Then
x = Split(Replace(Replace(Replace(Replace(Replace(oCel.Value, "H", ":", , , vbTextCompare), " - ", "#"), " -", "#"), "- ", "#"), "-", "#"))
For i = 0 To UBound(x)
y = Split(Trim(x(i)), "#")
If y(0) = "24:00" Then y(0) = "00:00"
If y(1) = "24:00" Then y(1) = "00:00"
If CSng(CDate(y(1))) < CSng(CDate(y(0))) Then t = t + 1
t = t + CSng(CDate(y(1))) - CSng(CDate(y(0)))
Next i
End If
Next oCel
TotHor = t
End Function
Function TotHorJ(r As Range) [COLOR="SeaGreen"]'Heures entre a et b.[/COLOR]
Application.Volatile
Dim a!, b!
Dim oCel As Range, i&, x, y, t!
a = CSng(CDate("06:00")) [COLOR="SeaGreen"]'Début des heures de jour.[/COLOR]
b = CSng(CDate("21:00")) [COLOR="SeaGreen"]'Fin des heures de jour.[/COLOR]
For Each oCel In r.Cells
If oCel.Value <> "OFF" And Not IsEmpty(oCel) Then
x = Split(Replace(Replace(Replace(Replace(Replace(oCel.Value, "H", ":", , , vbTextCompare), " - ", "#"), " -", "#"), "- ", "#"), "-", "#"))
With WorksheetFunction
For i = 0 To UBound(x)
y = Split(Trim(x(i)), "#")
If y(0) = "24:00" Then y(0) = "00:00"
If y(1) = "24:00" Then y(1) = "00:00"
If CSng(CDate(y(1))) < CSng(CDate(y(0))) Then
t = t + .Max(CSng(CDate(y(1))) - a, 0) + .Max(b - CSng(CDate(y(0))), 0)
Else
t = t + .Max(.Min(CSng(CDate(y(1))), b) - .Max(CSng(CDate(y(0))), a), 0)
End If
Next i
End With
End If
Next oCel
TotHorJ = t
End Function
Function TotHorN(r As Range) [COLOR="SeaGreen"]'Heures entre 0h00 et a plus heures entre b et 24h00.[/COLOR]
Application.Volatile
Dim a!, b!
Dim oCel As Range, i&, x, y, t!
a = CSng(CDate("06:00")) [COLOR="SeaGreen"]'Début des heures de jour.[/COLOR]
b = CSng(CDate("21:00")) [COLOR="SeaGreen"]'Fin des heures de jour.[/COLOR]
For Each oCel In r.Cells
If oCel.Value <> "OFF" And Not IsEmpty(oCel) Then
x = Split(Replace(Replace(Replace(Replace(Replace(oCel.Value, "H", ":", , , vbTextCompare), " - ", "#"), " -", "#"), "- ", "#"), "-", "#"))
With WorksheetFunction
For i = 0 To UBound(x)
y = Split(Trim(x(i)), "#")
If y(0) = "24:00" Then y(0) = "00:00"
If y(1) = "24:00" Then y(1) = "00:00"
t = t + CSng(CDate(y(1))) - CSng(CDate(y(0)))
If CSng(CDate(y(1))) < CSng(CDate(y(0))) Then
t = t + 1 - .Max(CSng(CDate(y(1))) - a, 0) - .Max(b - CSng(CDate(y(0))), 0)
Else
t = t - .Max(.Min(CSng(CDate(y(1))), b) - .Max(CSng(CDate(y(0))), a), 0)
End If
Next i
End With
End If
Next oCel
TotHorN = t
End Function[/B][/COLOR]