Counting numbers in changing arrays

Copper Contributor

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 PeriodHours Worked
431140
431140
431140
431140
4311412.5
4311412.5
4311412.75
431210
431210
431210
4312112.5
4312112.5
4312112.5
4312112.75

 

Thanks,
Tim

1 Reply

@TimOH2390 

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