Sub CalculateOvertime()
Dim lastRow As Long
lastRow = Cells(Rows.Count, “B”).End(xlUp).Row ‘ 獲取數據最后一行
For i = 2 To lastRow
Dim startTime As Date, endTime As Date, overtime As Double
startTime = Cells(i, "B").Value ' 上班時間
endTime = Cells(i, "C").Value ' 下班時間
If (endTime - startTime) * 24 > 9 Then
overtime = (endTime - startTime) * 24 - 9
End If
Cells(i, "D").Value = overtime '加班時間
Next i
End Sub
利唐i人事HR社區,發布者:hiHR,轉轉請注明出處:http://www.ynyjypt.com/hrnews/2024129338.html