I need assistance with calculating Reg and Daily/weekly OT

stefanoluigi

New Member
Joined
May 3, 2018
Messages
2
Hi everyone,

I need some assistance calculating regular and OT hours by day and week. Anything over 12 hours in a day and over 40 hours in a week. If the hours were already counted as OT for the daily over 12, they should not be counted for the over 40 hours for the respective week. This is an example of a time file that I have. I am looking for 1 summary line by employee that I have bolded below.

The employees don't all work 5 days, or may have multiple rows for one day.

Payroll Nameee idpay ratePay DateHoursWeekRegDay OTWeek OT
Jane Doe123456$11.9501/11/20166.8016.80
Jane Doe123456$11.9501/12/20169.2219.22
Jane Doe123456$11.9501/13/20166.0716.07
Jane Doe123456$11.9501/14/20165.8515.85
Jane Doe123456$11.9501/15/201612.07112.000.07
Jane Doe123456$11.9501/18/201614.00212.002.00
Jane Doe123456$11.9501/19/20168.1728.17
Jane Doe123456$11.9501/20/201612.00212.000.00
Jane Doe123456$11.9501/21/201616.00212.004.00
Jane Doe123456$11.9501/22/201612.02212.000.02
Bi Weekly Total 12345680.006.0816.17

<tbody>
</tbody>


Any assistance would be appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
adjust as needed...

Code:
Public Sub CalcHrs()
Dim vMsg
Dim rst   'As Recordset
Dim vRate, vTotReg, vTotOT
Dim vHrs As Single, vReg As Single, vOT As Single
Dim vCurrWk, vPrevWk, vCurrID, vPrevID

Const kiOffTotReg = 10
Const kiOffTotOT = 9
Const kiOffOtHrs = 8
Const kiOffRegHrs = 7
Const kiOffWk = 5
Const kiOffHrs = 4
Const kiOffRate = 2
Const kiOffID = 1

Const kiMaxReg = 40
Const kiMaxDay = 12

vPrevWk = "*&%"

Range("A2").Select
    While ActiveCell.Value <> ""
        vOT = 0
        vHrs = 0
        vCurrID = ActiveCell.Offset(0, kiOffID).Text
        vRate = ActiveCell.Offset(0, kiOffRate).Value
        vHrs = ActiveCell.Offset(0, kiOffHrs).Value
        vCurrWk = ActiveCell.Offset(0, kiOffWk).Value
        
        
        Select Case True   'reset the hours
            Case vPrevWk <> vCurrWk
                GoSub ResetHrs
            Case vCurrID <> vPrevID
                GoSub ResetHrs
        End Select

                '-----------------------
                'set the Reg Hrs, OT hrs.
                '-----------------------
        
        If vHrs > kiMaxDay Then
          vOT = vHrs - kiMaxDay
          vHrs = vHrs - vOT
        End If
        
        If vTotReg + vHrs >= kiMaxReg Then
           vReg = kiMaxReg - vTotReg
           vOT = vOT + (vHrs - vReg)
        Else
           vReg = vHrs
        End If
         
        vTotReg = vTotReg + vReg
        vTotOT = vTotOT + vOT
 
        ActiveCell.Offset(0, kiOffRegHrs).Value = vReg
        ActiveCell.Offset(0, kiOffOtHrs).Value = vOT
 
        vPrevID = vCurrID
        vPrevWk = vCurrWk
        
       ActiveCell.Offset(1, 0).Select  'next row
   Wend
   
GoSub ResetHrs
Range("J1").Value = "Weekly OT Total"
Range("k1").Value = "Weekly Reg Total"

MsgBox "DONE"
Exit Sub

ResetHrs:
ActiveCell.Offset(-1, kiOffTotReg).Value = vTotReg
ActiveCell.Offset(-1, kiOffTotOT).Value = vTotOT
vTotReg = 0
vTotOT = 0
Return

ErrRemove:
MsgBox Err.Description, , "CalcHrs():" & Err
End Sub
 
Upvote 0
Welcome to the board.

Here's a formula based solution:

ABCDEFGHIJ
1Payroll Nameee idpay ratePay DateHoursWeekRegDay OTWeek OT
2Jane Doe123456$11.95 1/11/20166.816.8
3Jane Doe123456$11.95 1/12/20169.2219.22
4Jane Doe123456$11.95 1/13/20166.0716.07
5Jane Doe123456$11.95 1/14/20165.8515.85
6Jane Doe123456$11.95 1/15/201612.071120.07
7Jane Doe123456$11.95 1/18/2016142122
8Jane Doe123456$11.95 1/19/20168.1728.17
9Jane Doe123456$11.95 1/20/201612212
10Jane Doe123456$11.95 1/21/2016162124
11Jane Doe123456$11.95 1/22/201612.022120.02
12Bi Weekly Total12345679.946.0916.17

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

Worksheet Formulas
CellFormula
H2=MIN(E2,12)
I2=IF(E2<=12,"",E2-H2)
H12=MIN(40,SUM(H2:H6))+MIN(40,SUM(H7:H11))
I12=SUM(I2:I11)
J12=SUM(H2:H11)-H12

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Note that the regular hours don't quite add up to 80, because the first week (H2:H6) doesn't quite add up to 40.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,575
Members
449,089
Latest member
Motoracer88

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