Total hours on call over holidays and shifts

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,659
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me?

I'm trying to create formulas to calculate the total number of hours each man is on call, segregated into the number of hours on call during waking hours, during sleeping hours, during waking hours on a holiday and during sleeping hours on a holiday. A period of being on call can span several days.

Here is some sample data and an exhibit of desired output. I include a column that illuminates how I manually calculated the hours for Man 5. [I cannot use VBA for this solution, but if one is available please do post it for the benefit of those who can.]

ABCDEFG
Bedtime
Awaken
In
Out
total hours
Awake=27,28,29,30,31,2 x16 hrs
Asleep=27,28,29,30,31,2 x8hrs + 3x4hrs
Holiday Awake=1 x 16hrs
Holiday Asleep=26 x2hrs + 1 x8hrs
total hours

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"]22:00[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]6:00[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="bgcolor: #FFF2CC"]Holidays[/TD]
[TD="align: right"]12/25/2016[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/26/2016[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"]1/1/2017[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="bgcolor: #FFF2CC"]On Call[/TD]
[TD="bgcolor: #FFF2CC"]Man 1[/TD]
[TD="bgcolor: #FFF2CC"]Man 2[/TD]
[TD="bgcolor: #FFF2CC"]Man 3[/TD]
[TD="bgcolor: #FFF2CC"]Man 4[/TD]
[TD="bgcolor: #FFF2CC"]Man 5[/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]12/23/2016 21:00[/TD]
[TD="align: right"]12/24/2016 09:00[/TD]
[TD="align: right"]12/24/2016 15:00[/TD]
[TD="align: right"]12/25/2016 23:00[/TD]
[TD="align: right"]12/26/2016 22:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]12/24/2016 03:00[/TD]
[TD="align: right"]12/24/2016 17:00[/TD]
[TD="align: right"]12/25/2016 23:00[/TD]
[TD="align: right"]12/26/2016 12:00[/TD]
[TD="align: right"]01/03/2017 04:00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="bgcolor: #FFE699, align: right"]6[/TD]
[TD="bgcolor: #FFE699, align: right"]8[/TD]
[TD="bgcolor: #FFE699, align: right"]32[/TD]
[TD="bgcolor: #FFE699, align: right"]13[/TD]
[TD="bgcolor: #FFE699, align: right"]174[/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]
[TD="bgcolor: #FFF2CC"]Hours On Call[/TD]
[TD="bgcolor: #FFF2CC"]Man 1[/TD]
[TD="bgcolor: #FFF2CC"]Man 2[/TD]
[TD="bgcolor: #FFF2CC"]Man 3[/TD]
[TD="bgcolor: #FFF2CC"]Man 4[/TD]
[TD="bgcolor: #FFF2CC"]Man 5[/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]

[TD="bgcolor: #F8CBAD, align: right"]1[/TD]
[TD="bgcolor: #F8CBAD, align: right"]8[/TD]
[TD="bgcolor: #F8CBAD, align: right"]7[/TD]
[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]96[/TD]

[TD="align: center"]15[/TD]

[TD="bgcolor: #F8CBAD, align: right"]5[/TD]
[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]2[/TD]
[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]52[/TD]

[TD="align: center"]16[/TD]

[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]22[/TD]
[TD="bgcolor: #F8CBAD, align: right"]6[/TD]
[TD="bgcolor: #F8CBAD, align: right"]16[/TD]

[TD="align: center"]17[/TD]

[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]0[/TD]
[TD="bgcolor: #F8CBAD, align: right"]1[/TD]
[TD="bgcolor: #F8CBAD, align: right"]7[/TD]
[TD="bgcolor: #F8CBAD, align: right"]10[/TD]

[TD="align: center"]18[/TD]

[TD="bgcolor: #FFE699, align: right"]6[/TD]
[TD="bgcolor: #FFE699, align: right"]8[/TD]
[TD="bgcolor: #FFE699, align: right"]32[/TD]
[TD="bgcolor: #FFE699, align: right"]13[/TD]
[TD="bgcolor: #FFE699, align: right"]174[/TD]
[TD="align: right"][/TD]

</tbody>
Sheet22
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I would like to offer a solution for you, but make a copy first and try it out.

I will give you formulas for column " F " and then copy them over to the left. ( I hope I thought of everything )

F14 =IF(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))>=$B$1,0,IF(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$2,(($B$1-$B$2)*24),($B$1-TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24))+IF(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<=$B$2,0,IF(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$1,(($B$1-$B$2)*24),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))-$B$2)*24))+(INT(F$10)-INT(F$9)-1)*(($B$1-$B$2)*24)-F$16

F15 =IF(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))>=$B$1,24-TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))*24,24-($B$1*24))+IF(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$2,($B$2-TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24,0)+(INT(F$10)-INT(F9)-1)*((24-($B$1*24))+($B$2*24))+IF(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>=$B$2,($B$2*24),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))*24))+IF(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$1,(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))-$B$1)*24,0)-F17

F16 =IF(INT(F$9)=$B$4,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),IF((($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24)>($B$1-$B$2)*24,($B$1-$B$2)*24,($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24),0),0)+IF(INT(F$9)=$B$5,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),IF((($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24)>($B$1-$B$2)*24,($B$1-$B$2)*24,($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24),0),0)+IF(INT(F$9)=$B$6,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),IF((($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24)>($B$1-$B$2)*24,($B$1-$B$2)*24,($B$1-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))))*24),0),0)+IF(INT(F$10)=$B$4,IF(AND((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>=$B$2),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<=$B$1)),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))-$B$2)*24,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$1),($B$1-$B$2)*24,0)),0)+IF(INT(F$10)=$B$5,IF(AND((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>=$B$2),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<=$B$1)),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))-$B$2)*24,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$1),($B$1-$B$2)*24,0)),0)+IF(INT(F$10)=$B$6,IF(AND((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>=$B$2),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<=$B$1)),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))-$B$2)*24,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$1),($B$1-$B$2)*24,0)),0)+IF(AND(INT(F$10)>$B$4,INT(F$9)<$B$4),($B$1-$B$2)*24,0)+IF(AND(INT(F$10)>$B$5,INT(F$9)<$B$5),($B$1-$B$2)*24,0)+IF(AND(INT(F$10)>$B$6,INT(F$9)<$B$6),($B$1-$B$2)*24,0)

F17 =IF(INT(F$9)=$B$4,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),24-($B$1*24),24-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24)+IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))>$B$2),0,($B$2*24)-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24),0)+IF(INT(F$9)=$B$5,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),24-($B$1*24),24-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24)+IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))>$B$2),0,($B$2*24)-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24),0)+IF(INT(F$9)=$B$6,IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))<$B$1),24-($B$1*24),24-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24)+IF((TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9))>$B$2),0,($B$2*24)-(TIME(HOUR(F$9),MINUTE(F$9),SECOND(F$9)))*24),0)+IF(INT(F$10)=$B$4,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<$B$1),0,((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24)-($B$1*24))+IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$2),($B$2*24),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24),0)+IF(INT(F$10)=$B$5,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<$B$1),0,((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24)-($B$1*24))+IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$2),($B$2*24),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24),0)+IF(INT(F$10)=$B$6,IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))<$B$1),0,((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24)-($B$1*24))+IF((TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10))>$B$2),($B$2*24),(TIME(HOUR(F$10),MINUTE(F$10),SECOND(F$10)))*24),0)+IF(AND(INT(F$10)>$B$4,INT(F$9)<$B$4),24-($B$1*24)+($B$2*24),0)+IF(AND(INT(F$10)>$B$5,INT(F$9)<$B$5),24-($B$1*24)+($B$2*24),0)+IF(AND(INT(F$10)>$B$6,INT(F$9)<$B$6),24-($B$1*24)+($B$2*24),0)

F18 =SUM(F$14:F$17)
 
Upvote 0
Chrisdontm, thanks for you efforts...your monumental efforts. No doubt you nearly had a seizure when trying to nest all those IF statements!

I noted that the formulas for each row item are inter-dependant with the exception of Rows 16 & 17. And I noted there is one little problem in the F17 formula: there is an extra space in some of the S ECOND functions.

Other than that, it works! It provides the desired result. But this solution (like any formulaic algorithm that achieves it) is so unwieldy most people would give up trying to create an algorithm that calculates net working hours and net non-working hours over working and non-working days. I see questions such as mine all over the Forum and there seems to be no easy solution.

But there should be! MS created the NETWORKDAYS function, so there should be no reason they can't create a NETWORKHOURS function too. Please go here, sign up, vote for the creation of this type of function, and post a link to this Thread in a comment. https://excel.uservoice.com/forums/...0730205-create-networkhours-as-a-new-function
 
Last edited:
Upvote 0
Oops: the desired output for Man3 was stated wrong by me. It should have been: 7, 2, 16, 7 (=32)
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top