Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

in very much need of a formula to calculate overtime

0

Hi,

First of all i would like to appreciate you all for doing such a great work and having each others back, So thank you all for your time and efforts.

My name is Nasr, and I'm in need of a formula to calculate overtime as mentioned in the attached table.

* In our shop overtime is stated to calculated after 3 hours of duty.

* Overtime will be calculated in hours, minutes will not be considered at all.

Answer
Discuss

Discussion

 1) Overtime will start exactly after 3 hours from the duty start time. (e.g. if the duty start time is 07:25, overtime starts from 10:25. and duty finishing time is 11:25, he will get 1hr as Overtime.)
if his duty finishes in 11:45, then also he will get 1hr overtime
if his duty finishes in between 11:25 - 12:24 he will get 1hr overtime

if his duty finishes in 12:25, then he will get 2hr overtime
if his duty finishes in 13:25, then he will get 3hr overtime

2) overtime hours will be rounded in hours only, no minutes will be counted (e.g. as shown in the spreadsheet. after deducting the first 3hrs from starting time, if he gets 1hr 30min overtime, then it will be shown in the cell as 1 only. (no minutes). if his overtime counts to 1hr 59min, then also it will be counted as 1hr of overtime)

   3) It's not a problem if overtime goes past the start of the next shift, cox next shift means a different person, and his overtime will be calculated separately as shown in the table.
Nasr (rep: 4) Feb 3, '21 at 4:37 am
Thanks Nasr, I answered anyway and withdrew my question.
John_Ru (rep: 6142) Feb 3, '21 at 4:38 am
Add to Discussion

Answers

0
Selected Answer

Hi Nasr

Please see the attached revision to your sheet which shows this siolution.

An example of the formula to use (for the rules in your question/sheet) is this (e.g. in cell D4):

=MAX(0,ROUNDDOWN(MOD(B4-A4,1)*24,0)-3)

The key bit (in bold above) calculates the time difference between finish and start times AND will work over midnight- see how it works via Don's excellent tutorial Calculate Hours Worked - Day or Night Shift & Breaks in Excel. That also shows you how to allow for breaks - essentially using the same formula to calculate the time on breaks then subtracting it from the whole shift.

Around that is the ROUNDDOWN function, ROUNDDOWN(<<shift time>>0), removing the minutes by rounding to 0 decimal places. I subtract 3 from that but that could produce a negative number so around that I add the MAX function with 0 as the other argument- that means the overtime is the maximum of zero or the subtracted time (i.e. if the time subtraction is less than zero, it will show zero, if more than 3 hours were worked, it will be the number of whole hours overtime).

Note that the cells using this formula should be formatted as a number (not General)

Hope this is what you need. 

Discuss

Discussion

Wow, it's working. I can't believe how much load of work you just relieved me from. thanks a lot for that.

Thank you sir.
Nasr (rep: 4) Feb 3, '21 at 4:57 am
That's good Nasr- hope you can save me time some day!
John_Ru (rep: 6142) Feb 3, '21 at 4:59 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login