我需要从另一个模块(在同一工作簿中)调用先前制作的UDF,以构建另一个UDF。如何调用第一个函数?
这是针对Excel VBA的。我已经建立了我的第一个函数,该函数可以计算特定时间的产品账面价值。它位于名为“ BookValue”的模块中,并且该函数称为“ BookVal”。我尝试在下一个函数中使用Application.BookVal(args)作为应用程序调用它,在使用UDF()作为UDF的情况下尝试调用它,最近一次是通过键入NewFunction = BookValue(BookVal)进行下一步。...没有任何效果。全部返回#VALUE。
这是我的代码:
Option Explicit
Function BookVal(UseLife As Single, ResaleAge As Single, PurchPrice As Double, SalVal As Double) As Double
BookVal = PurchPrice - ((PurchPrice - SalVal) / UseLife) * ResaleAge
End Function
Function PostTaxSale(UseLife As Double, ResaleAge As Double, TaxRate As Double, ResaleVal As Double, PurchPrice As Double, SalVal As Double, BookVal As Double) As Double
PostTaxSale = BookVal(UseLife, ResaleAge, PurchPrice, SalVal)
PostTaxSale = ResaleVal - PostTaxSale
PostTaxSale = Tax * PostTaxSale
PostTaxSale = ResaleVal - PostTaxSale
End Function
这将产生#VALUE
但是我希望代码从选定的单元格中提取参数作为参数,并返回方程式的结果: 税后转售价值=转售价值-税额*(转售价值-帐面价值)。
答案 0 :(得分:0)
您必须提供所有要求的条件:
Function BookVal(UseLife As Double, ResaleAge As Double, PurchPrice As Double, SalVal As Double) As Double
BookVal = PurchPrice - ((PurchPrice - SalVal) / UseLife) * ResaleAge
End Function
Function PostTaxSale(UseLife As Double, ResaleAge As Double, TaxRate As Double, ResaleVal As Double, PurchPrice As Double, SalVal As Double) As Double
PostTaxSale = BookVal(UseLife, ResaleAge, PurchPrice, SalVal)
PostTaxSale = ResaleVal - PostTaxSale
PostTaxSale = TaxRate * PostTaxSale
PostTaxSale = ResaleVal - PostTaxSale
End Function