gpt4 book ai didi

excel - 在另一个 UDF 中调用 UDF

转载 作者:行者123 更新时间:2023-12-04 20:28:32 27 4
gpt4 key购买 nike

我需要从另一个模块(在同一个工作簿中)调用以前制作的 UDF 来构建另一个 UDF。如何调用第一个函数?

这适用于 Excel VBA。我已经构建了我的第一个函数,它计算产品在特定时间的账面值(value)。它位于一个名为“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

但我希望代码从选定的单元格中提取作为参数并返回等式的结果:
税后转售值(value) = 转售值(value) - 税收 *(转售值(value) - 账面值(value))。

最佳答案

您必须提供所有被询问的标准:

 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

关于excel - 在另一个 UDF 中调用 UDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54262183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com