I started working on formula (as the subforum heading suggests, but it quickly started to grow. So gave up and prepared short UDF - a small macro which can be used the same way as build-in functions. The only difference is that macros have to be enabled in excel.
Have a look on attached file and code below. I tried to use self explanatory variable names.
calling function can be seen in the spreadsheet - first argument is relative address of the registered time, and two other are ranges with absolute addresses of work start-end and breaks (you are no longer limited to 3 ;-) ).
Function takt(r_end As Range, r_time As Range, r_breaks As Range) As Variant
Dim i As Integer, t_start As Double, t_end As Double, t_break As Double, breaks
Application.Volatile
If r_end.Cells.Count = 1 And r_time.Cells.Count = 2 And r_breaks.Columns.Count = 2 Then
t_start = IIf(r_end.Offset(0, -1) <> r_end.Offset(-1, -1), r_time(1), r_end.Offset(-1, 0))
t_end = WorksheetFunction.Min(r_end, r_time(2))
breaks = r_breaks.Value
For i = 1 To UBound(breaks) 'correction of start/end
breaks(i, 2) = breaks(i, 2) / (24 * 60) + breaks(i, 1)
If t_start >= breaks(i, 1) And t_start <= breaks(i, 2) Then t_start = breaks(i, 2)
If t_end >= breaks(i, 1) And t_end <= breaks(i, 2) Then t_end = breaks(i, 2)
Next i
For i = 1 To UBound(breaks) 'whole breaks inside
If t_start <= breaks(i, 1) And t_end >= breaks(i, 2) Then t_break = t_break + breaks(i, 2) - breaks(i, 1)
Next i
takt = (t_end - t_start - t_break) * 24 * 60
Else
takt = "bad data"
End If
End Function
Bookmarks