Formula to calculate overtime hours not working consistently - excel

Edit: It now calculates overtime after implementing Vincent's solution in the comments
My girlfriend works from home 6 hours a day and gets to make her own hours. She asked me to make a time sheet for her that she can enter her start and end times into and will automatically calculate her hours. It calculates the total hours worked no problem (so long as they don't go pass midnight), but I wanted to also have it track overtime hours for her.
I have a formula that should work, but the problem is that if all the start and end times on a given day are both AM or both PM then it will not calculate the overtime hours no matter how much the total hours surpass 6 hours. However, as soon as you enter in a time value that starts at an AM time and ends at a PM time, such as 11:00 to 14:00, then it calculates the total overtime hours for the day just fine.
Here's a screenshot of the time sheet with times entered with total hours above 6, but no start and end time crossing from AM to PM:
Here's an example where the the last time entered on the first day now goes from an AM time to a PM time. Notice that the overtime hours are now being calculated accurately.
The VBA generating the formulas that calculates the hours looks like this:
Sub calcHours(ByVal numDays As Integer)
Dim newWeekRow As Integer: newWeekRow = 0
With Sheets("timesheet")
'Add the formula to calculate hours for the day
Range(Cells(5, 17), Cells(numDays + 4, 17)).FormulaR1C1 = _
"=SUM((RC[-2] - RC[-3]) + (RC[-4] - RC[-5]) + (RC[-6] - RC[-7]) + (RC[-8] - RC[-9]) + (RC[-10] - RC[-11]) + (RC[-12] - RC[-13]))"
'Add formula to calculate overtime hours
Range(Cells(5, 19), Cells(numDays + 4, 19)).FormulaR1C1 = _
"=IF(RC[-2]-(6/24) > 6/24, RC[-2]-(6/24), 0)"
'Add the formula to calculate hours for the week
For ctr = 1 To numDays
If (Cells(4 + ctr, 2).Value = "Saturday") Then 'found the end of the week
If (newWeekRow = 0) Then 'end of the first week
Cells(4 + ctr, 18).FormulaR1C1 = "=SUM(R5C[-1]:RC[-1])"
newWeekRow = 4 + ctr
Else
Cells(4 + ctr, 18).FormulaR1C1 = "=SUM(R[-6]C[-1]:RC[-1])"
newWeekRow = 4 + ctr
End If
End If
If (ctr = numDays) Then 'reached the end of the last week
Cells(4 + ctr, 18).FormulaR1C1 = "=SUM(R" & newWeekRow + 1 & "C[-1]:RC[-1])"
End If
Next ctr
'Add formula to calulate total hours for the month
With Cells(5 + numDays, 17)
.FormulaR1C1 = "=SUM(R[-" & numDays & "]C:R[-1]C)"
.Font.Bold = True
End With
End With
End Sub

Currently your formula for suming the hours in the week is essentially:
=SUM(E5-D5,G5-F5,I5-H5,K5-J5,M5-L5, O5-N5)
The problem is that when you go past midnight you have no way of indicating that the time is the following day. Since Time is stored as a decimal and date is stored as the integer, and by default, when only time is entered, 0 is the integer for the day. All you need to do is add 1 to the time when they out time is less than the in time. Going to cheat a bit and assume there will never be more than a 24 hour period between in and out. So with that cheat in mind and that boolean True and False get converted to 1 and 0 respectively when going through a math operator, you could adjust your formula as follows:
=SUM(E5+(E5<D5)-D5,G5+(G5<F5)-F5,I5+(I5<H5)-H5,K5+(K5<J5)-J5,M5+(M5<L5)-L5, O5+(O5<N5)-N5)
Alternatively you could record the hours on the day they were worked on, not broken by the time you slept overnight as the delineater for the day. Ie if you work from 2300 on monday to 0100 on tuesday, then record monday as time in 2300 and time out as 23:59, and Tuesday record time in as 00:00 and time out as 01:01. Note the added 1 minute to the time out. This is to make up for the missing minute between 23:59 and 24:00 (which does not technically exist in excel but does work with some operations)
As for the overtime calculation see Vincent G's comment. Another spin on that formula could be:
=MAX(Q5-6/24,0)
You will need to change the cell references to match your VBA programming needs. Both formulas correct overtime issue calculation and start and end time crossing midnight.

First, if you go over midnight, here's what I would do:
Going over midnight means the hours will be negative. In that case, do an IF statement where if the result is a negative number, simply add 24 hours (or 1 day) to the result.
Second, couldn't you calculate the overtime without VBA by simply subtracting 6 hours from total working hours for the day?
I'm not too familiar with VBA, so if I'm missing something blatantly obvious, please forgive me.

Related

How to get the Week of the month (1:6)

We can find different approaches to determining the week of the month, and even though there are many pages on 1:4 and/or 1:5, there is very few around 1:6 approach.
So to give you a bit of the context, I am working with a pivot table in Excel which gets its values from a Power Query source.
In Power Query, there is a function Date.WeekOfMonth which takes in the date and returns a number between 1 and 6.
In this definition, weeks start from Sunday and ends on Saturday.
So, for example, the first two days of October 2021 -i.e. Fri & Sat- fall in the 1st week of Oct, while the 3rd day of Oct 2021 starts the second week, and then the last day of October 2021,i.e. Oct 31, is the only day in the 6th week.
I had an automation task on hand in which I needed to pull data from the Power Query-generated pivot, so I had to implement a piece of code in VBA which calcs weeks the same.
Unfortunately, I couldn't find any prepared snippet, so after implementing I though it might worth sharing.
(Any comments and suggestions appreciated)
The DatePart function is perfect for this. Using DatePart with the interval set to "weeks" you can find the week of a given date. Then you subtract the number of weeks before the first day of that month (which sets the first day to week = 1).
Function WeekNumOfDate(D As Date) As Integer
WeekNumOfDate = DatePart("ww", D) - DatePart("ww", DateSerial(Year(D), Month(D), 1)) + 1
End Function
Here is a second version of the function that has the ability to set the FirstDayOfWeek argument:
Function WeekNumOfDate(D As Date, Optional FirstDayOfWeek As VbDayOfWeek = vbSunday) As Integer
WeekNumOfDate = DatePart("ww", D, FirstDayOfWeek) - DatePart("ww", DateSerial(Year(D), Month(D), 1), FirstDayOfWeek) + 1
End Function
As an example for using FirstDayOfWeek: With FirstDayOfWeek set to vbThursday, the date "Nov 5th, 2021" will return as Week 2, whereas it would by default be counted as Week 1. November 1st to 3rd of 2021 will be week 1, and then 4th to 10th will be week 2.
Its implementation in VBA is:
Function WeekOfMonth(My_Date As Date)
If Day(My_Date) > Day(My_Date - 1) And Weekday(My_Date) > Weekday(My_Date - 1) Then
WeekOfMonth = WeekOfMonth(My_Date - 1)
ElseIf Day(My_Date) > Day(My_Date - 1) And Weekday(My_Date) < Weekday(My_Date - 1) Then
WeekOfMonth = WeekOfMonth(My_Date - 1) + 1
Else
WeekOfMonth = 1
End If
End Function
Note that even though the above function is recursive, its time and space complexity is an expression of order N, which here cannot exceed 31.

Excel formula to calculate elapsed minutes between 2 date timestamps only counting minutes during work hours

I have an excel sheet with about 50,000 records where I need to find the number of minutes between two date timestamps but I need to exclude any minutes that occurred during the times we are not working.
Our schedule is M-F 8:30am-5:30pm, Saturdays 8:30am-1:30pm
We don't work Sundays or holidays.
As an example
Cell B2: [7/3/2020 2:16:21 PM]
Cell C2: [7/6/2020 9:20:23 AM]
The manually calculated answer for this one should be about 244 minutes. Task started Friday afternoon, Saturday was a holiday, don't work Sundays, task completed at 9:20am on Monday.
Usually, I come here and start writing a question and by the time I've understood my own problem well enough to post a question I have figured it out on my own but not this time! Help!
Update:
#ForwardEd shared this...
=((I2-H2)
-MAX(0,(NETWORKDAYS.INTL(H2,I2,"0000011",$M$2:$M$12)-1+(WEEKDAY(I2,1)=7)))*TIME(15,0,0)
-MAX(0,(NETWORKDAYS.INTL(H2,I2,"1111101",$M$2:$M$12)-(WEEKDAY(I2,1)=7)))*TIME(19,0,0)
-NETWORKDAYS.INTL(H2,I2,"1111110",$M$2:$M$12)-(NETWORKDAYS.INTL(H2,I2,"0000000")
-NETWORKDAYS.INTL(H2,I2,"0000000",$M$2:$M$12)))*24*60
Where H:H is the Start Date Timestamp and I:I is the Response Date Timestamp and M2:M12 contains my holiday list.
It worked beautifully until I ran into an example like this:
H2 - 07/26/2020 7:48:45 PM
I2 - 07/27/2020 8:57:58 AM
The net result was -650.78333. It looks like anything that starts one one day and ends on the next is coming back as negative.
We want to measure the average response time in minutes for the applications that require manual underwriting. These start timestamps are times that loan applications were received online so they could come in any time of day. The stop times are timestamps that represent the system recorded response time. i.e. the timestamp where an underwriter first did something with the loan application. If a loan application was received at 7pm and was not auto-decisioned then a manual underwriter will need to do something with it the next day when we start working.
If that application came in at 7pm on Wed and is decisioned by an underwriter at 8:46am on Tuursday, we would want to document 16 minutes for that application - not 826 counting the hours between 7pm and 8:30am.
What you want to look at is NETWORKDAYS.INTL. Use this in conjunction with the custom settings to determine the number of Saturdays, Sundays and for the number of days in between your start and end time. You know you have X amount of time per day that is non working time, and Y amount per Saturday.
Then you formula in essence becomes
(End time - start time) - X * No. Weekdays - Y * No. Saturdays - No. Sundays - No. Holidays
Now there will be some tricks in there in order to count your days. but that is the gist of what it boils down to in a formula.
The formulas that are doing the brunt of the work are:
WORKDAY
NETWORKDAYS.INTL
TIME
I avoided the use of an if statement by using a boolean operation that excel will resolve from TRUE/FALSE to 1/0 when sent through a math operator. Side note: I read somewhere that this is also faster than an IF statement, but have no way of proving it and really does not matter on a small number of calculations.
WORKDAY
This formula will return the day of the week for a given date, and a set day of the week to be 1. It will be need in this solution to determine if the end date is a Saturday which has a value of 7 in default setup up as well when option 1 is picked. The format for the formula is:
WORKDAY(Excel Serial date, day 1 of the week)
For this solution
WEEKDAY(B3,1)
NETWORKDAYS.INTL
This formula will be used to count the number of specific days a start and an end date. It can exclude a custom weekend or count a custom week. If it is supplied with a list of dates that are holidays they can be excluded as well. The basic format of the formula is:
NETWORKDAYS.INTL(Start Date, End Date, Custom week choice or workweek pattern, range of holiday dates)
When entering the formula it will give you a list of predefined options for the weekend choices. It will not talk about the pattern.
The pattern is a string 7 digits long consisting of 1 or 0. 0's represents the days you want to count and 1's are days you want to ignore. An important part of the pattern is that the first entry is MONDAY. "1010111" would count only Tuesdays and Thursdays.
TIME
Excel stores date as an integer. 1 represents 1st of January 1900, 2 the 2nd of January 1900 and so on. Time is stored as a decimal or if you prefer the percentage/fraction of a day or 24 hour period. So rather than figuring out the math to determine what percentage of a day X number of hours is, it is simpler to let excel calculate it for us and make the number a little more understandable to someone who may be deciphering the formula later. The basic format of the formula is:
TIME(Hours, Minutes, Seconds)
So as stated earlier, 6 key components need to be determined:
X - Amount of non working time after a weekday
Y - Amount of non working time after a Saturday
Number of weekdays
Number of Saturdays
Number of Sundays
Number of holidays
1) Determine Weekday Non-Working Hours
Based on the supplied information that work day stops at 1730 and starts as 0830. There are a couple of ways of doing the math. Subtract the working hours from 24 hours or count the non work hours at the end of the day and add them to the non work hours at the start of the day.
24 - (17.5 - 8.5) = 15
or
(24 - 17.5) + (8.5 - 0) = 15
For this example 15 will be hard coded into the final formula
2) Determine Saturday Non-Working Hours
Similar to above. Note that we are ignoring Sunday as it is a designated non working day which we already know is 24 hours or 1 day. We are just interested in the time between end of shift Saturday and start of the next normal working Monday. So it really gets calculated the same with just with difference end of shift time.
24 - (13.5 - 8.5) = 19
or
(24- 13.5) - (8.5 - 0) = 19
For this example 19 will be hard coded into the final formula
3) Determine Number of Weekdays
Based on the description earlier of of NETWORKDAYS.INT and working with the assumption that holidays are stored in the range F2:F2, and using a pattern of "0000011" the number of weekdays the formula will be as follows:
=NETWORKDAYS.INTL(B2,B3,"0000011",F2)
For this example the formula is place in cell F6
4) Determine Number of Saturdays
Similar 3) adjust the pattern to only select Saturdays by using "1111101"
=NETWORKDAYS.INTL(B2,B3,"1111101",F2)
For this example the formula is place in cell F7
5) Determine Number of Sundays
Similar 4) adjust the pattern to only select Saturdays by using "1111110"
=NETWORKDAYS.INTL(B2,B3,"1111110",F2)
For this example the formula is place in cell F8
6) Determine Number of Holidays
To get the number of holidays there is not a direct way of doing it. Instead take the difference between all days counted without holidays being factored in and all days counted with holidays counted in.
=NETWORKDAYS.INTL(B2,B3,"0000000")-NETWORKDAYS.INTL(B2,B3,"0000000",$F$2:F2)
For this example the formula is place in cell F9
Now at this point I would love to say just substitute all of the above into the generic formula, but there are a couple of special cases that need to be taken care of. You may have also noted I have not used the WEEKDAY formula yet.
So in order to count the number of days to which X is going to apply, its really the number of days minus 1. The minus 1 is because you want to cont the intervals between days, not the number of days themselves. This gets a little bit more trickier when the end day is a Saturday because there is still an interval there but Saturday is not counted as a weekday. So the True count for number of weekday intervals is:
=MAX(0,(F6-1+(WEEKDAY(B3,1)=7)))
I originally had the MAX(0, calc) in there to prevent the posibility of the day count being negative. After arriving at this final format it may not be needed and you might get away with the following but its untested:
=F6-1+(WEEKDAY(B3,1)=7)
This same concept needs to be applied to your Saturday count. If you job ends on Saturday you do not need to subtract the non working hours after the last Saturday. You formula will look like:
=MAX(0,(F7-(WEEKDAY(B3,1)=7)))
and again further testing is required to make sure MAX can be removed, but if it can then the formula would look like:
=F7-(WEEKDAY(B3,1)=7)
So now with the understanding how dates and times are stored, determine the time difference between start end end time and subtract all the non working hours.
=(B3-B2)-MAX(0,(F6-1+(WEEKDAY(B3,1)=7)))*TIME(15,0,0)-MAX(0,(F7-(WEEKDAY(B3,1)=7)))*TIME(19,0,0)-F8-F9
Now you will not want to use helper cells, so you can take each of the individual formula from F6 to F9 and wind up with:
=(B3-B2)-MAX(0,(NETWORKDAYS.INTL(B2,B3,"0000011",F2)-1+(WEEKDAY(B3,1)=7)))*TIME(15,0,0)-MAX(0,(NETWORKDAYS.INTL(B2,B3,"1111101",F2)-(WEEKDAY(B3,1)=7)))*TIME(19,0,0)-NETWORKDAYS.INTL(B2,B3,"1111110",F2)-(NETWORKDAYS.INTL(B2,B3,"0000000")-NETWORKDAYS.INTL(B2,B3,"0000000",$F$2:F2))
The formula looks unruly, but is easier to understand when broken down into its parts.
Now the last step is to get the answer to display in minutes. There are two choices.
You can leave it as it is in an excel serial date format and change the formatting of to a custom format of [m]. The [ ] will force it into minutes and prevent spill over to hours. It will also round to the nearest minute.
You can convert the results to minutes by multiplying by 24*60 and the value will be in minutes and decimal of minutes.
Note that:
A11 has Time formatting applied
A12 has General formatting applied
A14 has custom formatting of [m] applied
It should be something like this:
Create a calendar table with the workinghours for each days in the year you have data in
Date | StartTime | End time
1/1/2020 1/1/2020 8:30:00 PM 1/1/2020 5:30:00 PM
...
7/3/2020 7/3/2020 8:30:00 PM 7/6/2020 5:30:00 PM
...
12/31/2020
Then paste this code in a module
Function CalcDays(dStart As Date, dEnd As Date, daysCalendar As Range)
Dim Cell As Range
Dim MinDaysCalendar As Date, MaxDaysCalendar As Date
Dim aWSF As WorksheetFunction
Set aWSF = Application.WorksheetFunction
'check the minimum en the maximum date in the calendar
With aWSF
MinDaysCalendar = .Min(daysCalendar)
MaxDaysCalendar = .Max(daysCalendar)
End With
'if the date you check is not in the calendar, exit the function
If dStart < MinDaysCalendar Or dStart > MaxDaysCalendar Then
MsgBox "Date not in calendar"
Exit Function
End If
If dEnd < MinDaysCalendar Or dEnd > MaxDaysCalendar Then
MsgBox "date not in calendar"
Exit Function
End If
'sum the time of all the dates between the start and the end
'pick min and max in order to start and stop at the right time per day
Dim tempTime As Integer
With daysCalendar
For i = 1 To .Rows.Count
If .Cells(i, 2).Value >= CLng(dStart) And .Cells(i, 3).Value <= CLng(dEnd) Then
daytime = aWSF.Max(.Cells(i, 2).Value, dStart) - aWSF.Min(.Cells(i, 3).Value, dEnd)
End If
tempTime = tempTime + daytime
Next i
End With
'return the total time
CalcDays = tempTime
End Function
You can call the function by typing =calcdays in a cell and then give the startDay, endDay and calendar column as parameters.
There might still be some flaws in this code but I think we can manage those.

Excel Time Comparison and Subtraction

I am trying to do a time subtraction in excel of 30 minutes and I am running into a speed bump. So the table I have are as follows.
Table "Schedule"
Column 1 is day of the week (Mon-Sun) (formated as general, as this is plain text)
Column 2 is start time of the shift (formated as h:mm AM/PM)
Column 3 is end time of the shift (formated as h:mm AM/PM)
Column 4 is duration of the shift (start to end) (formated by formula (TEXT(col3-col2,"h:mm")) )
Column 5 is paid hours (if the total hours is over 6.5 then subtract 0.5 hours for an unpaid lunch) (formula IF(col5>"6:30",col5-"0:30",D5) )
The issue is any time allotment over 10 hours start to end (where column 4, the duration hits 10 hours) no lunch is subtracted at all.
So...
Start 9:00 AM, End 6:59 PM, Hours Total 9:59, Hours Paid 9:29
But...
Start 9:00 AM, End 7:00 PM, Hours Total 10:00, Hours Paid 10:00
and that should obviously not happen. I can't find anything on google so I figured the excel gurus here may have some advice.
Thanks!
If your time columns are stores using excel's dedicated time format, this should be straightforward. Mixed data types are likely your problem.
First, be sure your time columns (columns 2 and 3) are set using the time function, i.e.,
=time(hours,minutes,seconds)
Then, you should be able to add and subtract easily.
Column 4: = column 3 - column 2
... then subtract 30 minutes also using the time() function:
Column 5: = if(column 4 > time(6,30,0),column 4 -time(0,30,0),column 4)
Excel stores time values from 0 to 1. So 24 hours=1, 12 hours=.5 etc. That means 6.5 hours=0.270833333 and .5 hours=0.020833333. As a result you can just do a simple if statement.
=IF(D2>0.270833333,D2-0.020833333,D2)
To turn it into a time format, is to just use excel's time formating options.

How to count hours in excel

I have xls file in following format
Name 1 2 3 4
John 09:00-21:00 09:00-21:00
Amy 21:00-09:00 09:00-21:00
Where 1,2,3,4 and so on represent days of current month,
09:00-21:00 - working hours.
I want to calculate salary based on the following conditions:
09:00-21:00 - 10$/hour
21:00-00:00 - 15$/hour
00:00-03:00 - 20$/hour
etc.
and so on (every hour can have it's own cost, for example 03:00-04:00 - 20$/hour, 04:00-05:00 - 19$/hour, etc.)
How can i accomplish this using only Excel (functions or VBA)?
P.S. Easy way: export to csv and process in python/php/etc.
Here is a non-VBA solution. It's a pretty nasty formula, but it works. I am sure it could be made even easier to use and understand with some more ingenuity:
Assuming the spreadsheet is set up like this:
Enter this formula in cell G1 and drag down for your data set:
=IF(ISBLANK(B2),"",IF(LEFT(B2,2)<MID(B2,FIND("-",B2)+1,2),SUMIFS($P$2:$P$24,$Q$2:$Q$24,">="&LEFT(B2,2),$Q$2:$Q$24,"<="&MID(B2,FIND("-",B2)+1,2)),SUMIF($Q$2:$Q$24,"<="&MID(B2,FIND("-",B2)+1,2),$P$2:$P$24)+SUMIF($Q$2:$Q$24,">="&LEFT(B2,2),$P$2:$P$24)))
To explain the formula in detail:
IF(ISBLANK(B2),"" will return a empty string if there is no time for a given person / day combination.
LEFT(B2,2) extracts the start-time into an hour.
Mid(B2,Find("-",B2)+1,2) extracts the end-time into an hour.
IF(LEFT(B2,2)<MID(B2,FIND("-",B2)+1,2) will check if the start-time is less than the end-time (meaning no over-night work). If the start-time is less than the end-time, it will use this formula to calculate the total cost per hour: SUMIFS($P$2:$P$24,$Q$2:$Q$24,">="&LEFT(B3,2),$Q$2:$Q$24,"<="&MID(B3,FIND("-",B3)+1,2))
If the start-time is higher than the end-time (meaning overnight work), it will use this formula to calculate: SUMIF($Q$2:$Q$24,"<="&MID(B3,FIND("-",B3)+1,2),$P$2:$P$24)+SUMIF($Q$2:$Q$24,">="&LEFT(B3,2),$P$2:$P$24)
The use of the Find("-",[cell]) splits the start-and- end times into values excel can use to do math against the Time / Cost table.
The formula in column Q of the Time / Cost table is =VALUE(MID(O2,FIND("-",O2)+1,2)) and turns the ending hour to consider the cost into a value Excel can use to add, instead of having the text from your original source format.
Do this in VBA! It is native to excel and is easy to learn. Functionally, I would loop through the table, write a function to calculate the dollars earned based on the info given. If you want your results to be live updating (like a formula in excel) you can write a user defined function. A helpful function might be an HoursIntersect function, as below:
Public Function HoursIntersect(Period1Start As Date, Period1End As Date, _
Period2Start As Date, Period2End As Date) _
As Double
Dim result As Double
' Check if the ends are greater than the starts. If they are, assume we are rolling over to
' a new day
If Period1End < Period1Start Then Period1End = Period1End + 1
If Period2End < Period2Start Then Period2End = Period2End + 1
With WorksheetFunction
result = .Min(Period1End, Period2End) - .Max(Period1Start, Period2Start)
HoursIntersect = .Max(result, 0) * 24
End With
End Function
Then you can determine the start and end time by splitting the value on the "-" character. Then multiply each payment schedule by the hours worked within that time:
DollarsEarned = DollarsEarned + 20 * HoursIntersect(StartTime, EndTime, #00:00:00#, #03:00:00#)
DollarsEarned = DollarsEarned + 10 * HoursIntersect(StartTime, EndTime, #09:00:00#, #21:00:00#)
DollarsEarned = DollarsEarned + 15 * HoursIntersect(StartTime, EndTime, #21:00:00#, #00:00:00#)
I have a method that uses nothing but formulas. First create a lookup table which contains every hour and rate in say columns K & L, something like this:
K L
08:00 15
09:00 10
10:00 10
11:00 10
12:00 10
13:00 10
14:00 10
15:00 10
16:00 10
17:00 10
18:00 10
19:00 10
20:00 10
21:00 15
22:00 15
23:00 15
Make sure you enter the hours as text by entering a single quote before the digits.
Then if your hours were in cell B2 you could then use this formula to calculate the total:
=SUM(INDIRECT("L"&MATCH(LEFT(B2,5),K2:K40,0)&":L"&MATCH(RIGHT(B2,5),K2:K40,0)))
All the formula is doing is getting the left and right text of your work time, using MATCH to find their positions in the lookup table which is used to create a range address which is then passed to SUM via the INDIRECT function.
If you need to worry about minutes all you need to do is create a bigger lookup table which holds every minute of the day. You may need to add some extra logic if your work days span midnight.

Derive an End date by Man hours and a start date in Excel-2010

I need a formula which calculates the End Date (with Time) when total Man Hours and Start Date are given. [Excel 2010]
Criteria:
1 Man Day = 8 Hours (1 hour is break time)
Work Start Time = 10:00
Work End Time = 19:00
1 Man Week = Mon - Fri
Holidays, if any, should not be counted
For example:
Cell E7 = Man Hours = 10 Hrs
Cell F7 = Start Date = 26-Jun-15 13:00
Cell G7 = End Date = ???? (Ideally 29-Jun-15 14:00)
*27th and 28th are weekends
Thank you!
margin of error for the estimate of duration from estimate of effort is too big for an hourly granularity to make any sense as long as real people and realistic plans are concerned
however, if we have an estimate of duration in working hours on the input (as opposed to calendar days/weeks/months which are more common units of duration estimates) and we need to calculate the end date-time, we could:
compute helper column with the would-be end hour if there were no closing hours (e.g. in cell H7, in Excel Date units = fractions of a day)
=MOD(F7, 1) + MOD(E7, 8)/24
check if the would-be hour is before the closing hours and adjust the end day + end time accordingly. If it's after, move to the next workday and adjust time, e.g. for simplicity assume all breaks are at the beginning of a day, so we can subtract the number of hours in a workday:
=IF(H7 <= 19/24,
WORKDAY(F7, E7/8, holidays) + H7,
WORKDAY(F7, E7/8 + 1, holidays) + H7 - 8/24)
assume you saved your national holidays on column I, you can try below in cell H7:
=IF(HOUR(F7+E7/24)>19,((F7+E7/24)-INT(F7+E7/24)-0.792)+(WORKDAY(F7,1,I:I))+0.417,F7+E7/24)

Resources