Function TotHorM(r As Range)
Application.Volatile
Dim a!, b!
Dim oCel As Range, x, i&, y, z, t!
a = CSng(CDate("08:00"))
b = CSng(CDate("12:00"))
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 + WorksheetFunction.Max(CSng(CDate(y(1))) - a, 0) + WorksheetFunction.Max(b - CSng(CDate(y(0))), 0)
Else
t = t + WorksheetFunction.Max(WorksheetFunction.Min(CSng(CDate(y(1))), b) - WorksheetFunction.Max(CSng(CDate(y(0))), a), 0)
End If
Next i
End If
Next oCel
TotHorM = t
End Function
Function TotHorS(r As Range)
Application.Volatile
Dim a!, b!
Dim oCel As Range, x, i&, y, z, t!
a = CSng(CDate("12:30"))
b = CSng(CDate("16:00"))
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 + WorksheetFunction.Max(CSng(CDate(y(1))) - a, 0) + WorksheetFunction.Max(b - CSng(CDate(y(0))), 0)
Else
t = t + WorksheetFunction.Max(WorksheetFunction.Min(CSng(CDate(y(1))), b) - WorksheetFunction.Max(CSng(CDate(y(0))), a), 0)
End If
Next i
End If
Next oCel
TotHorS = t
End Function