|
当同时打开2017表和折旧模板,操作2017表内容后再返回到折旧模板表后。为什么折旧模板中的自定义函数会出错?
不知道什么原因。请教!!!
Public Function 折旧(x, y)
Application.Volatile
t = Sheets("汇总表").[a4]
t1 = VBA.DateSerial(Year(t), Month(t), 0)
t2 = VBA.DateSerial(Year(t), Month(t) + 1, 0)
arr = Sheets("折旧表").Range("a5:o" & Sheets("折旧表").Cells(Rows.Count, 1).End(xlUp).Row)
For i = 2 To UBound(arr)
If arr(i, 15) = "" Then
If arr(i, 2) = x And arr(i, 7) <= t1 And y = "期初原值" Then 折旧 = 折旧 + arr(i, 6)
If arr(i, 2) = x And arr(i, 7) <= t2 And arr(i, 7) > t1 And y = "本月增加" Then 折旧 = 折旧 + arr(i, 6)
If arr(i, 2) = x And arr(i, 7) <= t2 Then
If y = "本月折旧" Then 折旧 = 折旧 + arr(i, 12)
If y = "上月累计折旧" Then 折旧 = 折旧 + arr(i, 13)
If y = "本月累计折旧" Then 折旧 = 折旧 + arr(i, 14)
End If
Else
If arr(i, 15) > t1 And arr(i, 15) <= t2 And y = "本月减少" Then 折旧 = 折旧 + arr(i, 6)
End If
Next i
End Function
主要是当前工作表转换后,function里找不到指定工作表了。只要限定当前工作簿即可。
当然不改也可以。在出错情况下,重新运行一遍即可。
|
|