Function DepositRate(Deposit):
If Deposit > 100000 Then
Rtaxa = 0.078
ElseIf Deposit <= 100000 And Deposit > 10000 Then
Rtaxa = 0.073
ElseIf Deposit <= 10000 And Deposit > 1000 Then
Rtaxa = 0.063
ElseIf Deposit <= 1000 And Deposit > 0 Then
Rtaxa = 0.055
Else
Rtaxa = "Negative Value"
End If
DepositRate = Rtaxa
End Function
Function NewDFV(Value, Year):
Call DepositRate(Value)
ValorFuturo = Deposit * (1 + Rtaxa) ^ (Year)
NewDFV = ValorFuturo
End Function
那么,我在这里做错了吗?
最佳答案
函数调用函数
Private Function GetDepositrate(...)...
同时将两个功能保留在同一个模块中。该功能仍然可用,只是未列出。 Option Explicit
Function GetDepositrate(ByVal Deposit As Double) As Double
Dim RTaxa As Double
If Deposit > 100000 Then
RTaxa = 0.078
ElseIf Deposit > 10000 Then
RTaxa = 0.073
ElseIf Deposit > 1000 Then
RTaxa = 0.063
ElseIf Deposit > 0 Then
RTaxa = 0.055
Else
' Negative Value - do nothing
End If
GetDepositrate = RTaxa
End Function
Function NewDFV(ByVal Deposit As Double, ByVal Year As Long) As Double
Dim RTaxa As Double: RTaxa = GetDepositrate(Deposit)
NewDFV = Deposit * (1 + RTaxa) ^ (Year)
End Function
关于excel - 如何在 VBA 中的另一个函数中调用一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71058457/