A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
For 5.3 hours in E4 we need a start time of 17:42 (18:00 to 23:00 are 5 hours).
The formulas in G:H are done with a UDF (a macro), I:J are done with formulas, choose what you like.
Columns G:H
G3: =(IntersectDateTime(C3,D3,$A$8,$B$8)+IntersectDateTime(C3,D3,$A$10,$B$10))*24
H3: =(IntersectDateTime(C3,D3,$A$7,$B$7)+IntersectDateTime(C3,D3,$A$11,$B$11))*24
drag down
Code:
Function IntersectDateTime(ByVal StartTime As Date, ByVal EndTime As Date, ByVal InTime As Date, ByVal OutTime As Date) As Date
Dim S As Date, E As Date
If InTime >= EndTime Then Exit Function
If OutTime <= StartTime Then Exit Function
If InTime > StartTime Then S = InTime Else S = StartTime
If OutTime < EndTime Then E = OutTime Else E = EndTime
IntersectDateTime = E - S
End Function
Columns I:J
I3: =(IF(C3>=$B$8,0,IF(D3<=$A$8,0,MIN(D3,$B$8)-MAX(C3,$A$8)))+IF(C3>=$B$10,0,IF(D3<=$A$10,0,MIN(D3,$B$10)-MAX(C3,$A$10))))*24
J3: =(IF(C3>=$B$7,0,IF(D3<=$A$7,0,MIN(D3,$B$7)-MAX(C3,$A$7)))+IF(C3>=$B$11,0,IF(D3<=$A$11,0,MIN(D3,$B$11)-MAX(C3,$A$11))))*24
drag down
Andreas.