Calculating Time Error

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077

Hello All,


I am running a formula that will count the number of employees scheduled at a particular time. (Each formula references a different hour). In addition to what is an incredibly long formula, I now have discovered that if a shift is scheduled to end past 23:59, then the entire shift will not be counted.
Can somebody assist me in fixing this, and if you have any hints of shortening this formula, that would be greatly appreciated.

Code:
=(SUM(IF(E$87:E$111<$B87,IF(F$87:F$111>$A87,IF(F$87:F$111<$B87,F$87:F$111,$B87)-IF(E$87:E$111>$A87,E$87:E$111,$A87))))*24)+(SUM(IF(E$113:E$137<$B87,IF(F$113:F$137>$A87,IF(F$113:F$137<$B87,F$113:F$137,$B87)-IF(E$113:E$137>$A87,E$113:E$137,$A87))))*24)+(SUM(IF(E$139:E$146<$B87,IF(F$139:F$146>$A87,IF(F$139:F$146<$B87,F$139:F$146,$B87)-IF(E$139:E$146>$A87,E$139:E$146,$A87))))*24)+(SUM(IF(E$148:E$156<$B87,IF(F$148:F$156>$A87,IF(F$148:F$156<$B87,F$148:F$156,$B87)-IF(E$148:E$156>$A87,E$148:E$156,$A87))))*24)

Thanks,

Andrew
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Here is a basic Example:
EmployeeStart TimeEnd Time
Joe
8:0014:00
Sara15:0021:00
Bob18:0000:30
Sam17:0023:30
Chad14:0019:00

<tbody>
</tbody>

Now my full sheet of course has more employees and 7 days of the week.
My current formula does work (It references other cells as well)
Here is the part that I am looking at:
2:00-3:001 Employee Working (Chad)
3:00-4:002 Employees Working (Chad,Sara)
4:00-5:002 Employees Working
5:00-6:003 Employees Working (Sam started his shift)
6:00-7:00Still 3, should be 4 (Bob)
7:00-8:002, should be 3. Chad is off shift

<tbody>
</tbody>
The problem is that if a shift runs past midnight (00:00) then the formulas completely ignore the entire shift, and I am not sure how to remedy it. That is the problem.
 
Upvote 0
We can get to your desired answer, I must tell you that it will be tomorrow night before I can work on it...
If someone else steps in that will be fine, otherwise I'll help you out...
 
Last edited:
Upvote 0
I am not completely following how you have things setup...
But, let me show you a formula of interest;
Suppose Bob's Start time in cell B4 is: 18:00
and his End time in C4 is just after midnight: 00:30

=MOD(C4-B4,1)*24

The MOD formula leaves you with the remainder after a division problem, ( The number one is what you are dividing it by )
When you take C4-B4 you will get a negative number, but you will be dropping off the integer and left with the portion of a day, times 24 ( Hours ), it will give you 6.5

But you must have the cell formatted as a Number to get the right answer...

I still don't mind helping, I just don't see how it is laid out;
What is in cell B87?
What is being totaled in E87:E111?
What is in A87?
 
Upvote 0
A87 & B87 are time ranges. Let's say they are 9:00 and 10:00, well, my formula looks at all the rows that I have employees and if their shift is between 9:00&10:00, then a value of 1 is returned for each person (rows 87:111)
So if row 87 had a shift from 8:00 to 14:00, then my formula would calculate that as, 9-10:00 falls in between 8-14:00.
Am I making sense?
 
Upvote 0
See if this is what you want?

A​
B​
C​
D​
E​
F​
1​
EmployeeStart TimeEnd Time
2:00:00 PM​
3:00:00 PM​
1​
2​
Joe
8:00:00 AM​
2:00:00 PM​
3:00:00 PM​
4:00:00 PM​
2​
3​
Sara
3:00:00 PM​
9:00:00 PM​
4:00:00 PM​
5:00:00 PM​
2​
4​
Bob
6:00:00 PM​
12:30:00 AM​
5:00:00 PM​
6:00:00 PM​
3​
5​
Sam
5:00:00 PM​
11:30:00 PM​
6:00:00 PM​
7:00:00 PM​
2​
6​
Chad
2:00:00 PM​
7:00:00 PM​
7:00:00 PM​
8:00:00 PM​
2​
F1=COUNTIFS($B$2:$B$6,"<="&D1,$C$2:$C$6,">"&E1)
copied down
 
Upvote 0
Still encountering the same issue where the row with a post midnight ending time does not get calculated.
 
Upvote 0
Hi,

Try this:
First insert an empty row on top of your data range. Then, if the end time is in Column C, type in time 4:00 and in Column D type in time 24:00. Starting under 24:00, type this formula
Code:
=IF(C2 < $C$1,C2+$D$1,C2)
In columns E and F, if you have the time range for calculating number of employees, then in column G use this formula
Code:
{=SUM(IF($B$2:$B$6<=E3,IF($D$2:$D$6>=F3,1,0)))}
and DON"T press enter, press ctrl+shift+enter to use it as an array formula. Then drag it down to required range.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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