Total hours on call over holidays and shifts

DRSteele

Well-known Member
Joined
Mar 31, 2015
Messages
2,640
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
1Bedtime22:00
2Awaken6:00
3
4Holidays12/25/2016
512/26/2016
61/1/2017
7
8On CallMan 1Man 2Man 3Man 4Man 5
9In12/23/2016 21:0012/24/2016 09:0012/24/2016 15:0012/25/2016 23:0012/26/2016 22:00
10Out12/24/2016 03:0012/24/2016 17:0012/25/2016 23:0012/26/2016 12:0001/03/2017 04:00
11total hours683213174
12
13Hours On CallMan 1Man 2Man 3Man 4Man 5
14Awake187096=27,28,29,30,31,2 x16 hrs
15Asleep502052=27,28,29,30,31,2 x8hrs + 3x4hrs
16Holiday Awake0022616=1 x 16hrs
17Holiday Asleep001710=26 x2hrs + 1 x8hrs
18total hours683213174

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet22
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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