Aug 15 2021 05:24 PM
Hi,
I need help with a payroll query.
I need to calculate overtime in each pay period. Each person can work over 10 hours in a shift one time per pay period, but the second, third or fourth time they do it they receive overtime. How do I get excel to calculate the overtime for each pay period?
Pay Period | Hours Worked |
43114 | 0 |
43114 | 0 |
43114 | 0 |
43114 | 0 |
43114 | 12.5 |
43114 | 12.5 |
43114 | 12.75 |
43121 | 0 |
43121 | 0 |
43121 | 0 |
43121 | 12.5 |
43121 | 12.5 |
43121 | 12.5 |
43121 | 12.75 |
Thanks,
Tim
Oct 14 2021 12:55 PM
I have only managed to write very easy VBA code to calculate overtime for each pay period. I entered table in range A1:B15. Enter pay period number in D1 and execute macro and overtime for the chosen pay period is displayed in D2.
Sub Overtime()
Dim i As Integer
Dim z As Integer
Dim j As Double
z = 0
For i = 2 To 15
If Cells(i, 1).Value = Cells(1, 4).Value And Cells(i, 2).Value > 10 Then
z = z + 1
If z >= 2 Then
j = j + Cells(i, 2).Value - 10
Else
End If
Else
End If
Next i
Cells(2, 4).Value = j
End Sub