我想设置一个用户定义的函数,用以下代码计算员工进出时间的工时。它在VBA
代码窗口中运行良好,但它没有显示在电子表格的功能栏下。任何线索?
Function HoursWorked()
clockin = [b2]
clockout = [c2]
HoursWorked = Round(DateDiff("n", clockin, clockout) / 60, 2)
[d2] = HoursWorked
MsgBox HoursWorked
End Function
答案 0 :(得分:1)
VBA
[屏幕左侧]中写的功能都出现在excel的功能栏中
也许您想尝试下面编辑的版本,而不必总是使用单元格B2
,C2
和D2
。我在单元格=HoursWorkedv2(B2,C2)
E4
Public Function HoursWorkedv2(ByVal Time1 As Date, ByVal Time2 As Date)
clockin = Time1
clockout = Time2
HoursWorkedv2 = Round(DateDiff("n", clockin, clockout) / 60, 2)
End Function