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,转转请注明出处:https://www.ihr360.com/hrnews/2024129338.html