我有一个UDF,如果开始日期小于或等于现金流中列标题的日期,则该UDF将从工作簿的另一张表中提取行项目费用并输入费用。计算时代码可以正常工作,但是一旦移到另一张纸上,我就会得到#Value!
我已经尝试过Application.Volatile,但不能解决问题。
Function Expense(Item, Month, Cost_Code)
Dim COST As Variant
Dim START As Date
Dim RNG As Range
With Worksheets("Unit Costs").Range("C1:C100")
Set RNG = .Find(what:=Item.Value, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
searchdirection:=xlNext)
If Not RNG Is Nothing Then
If RNG.Offset(0, Cost_Code + 5).Value = "TBD" Then
Expense = "TBD"
End
Else:
COST = RNG.Offset(0, Cost_Code + 5).Value
START = RNG.Offset(0, 1).Value
End If
Else:
Expense = "Unk Exp"
End If
End With
If START >= Month Then
Expense = 0
Else: Expense = COST
End If
End Function