如何改进DCF模型的原始VBA代码?

时间:2017-03-29 05:12:54

标签: excel vba excel-vba loops primitive

我是VBA的新手,我一直在努力创建一个程序,允许我采用起始现金金额,按一定折扣率折扣该金额,并将贴现率乘以n年来找到给定基于给定年数的贴现现金流量。有没有人有任何关于如何使这个代码更有效的提示?另外,使用循环将不同现金总和加在一起的一些提示,例如“(100 / 1.01)+(100 / 1.01 ^ 2)+(100 / 1.01 ^ 3)?”提前致谢!

Sub DCF()

Dim z As Double, CashFlow As Double, DiscRate As Double, Periods As Double

CashFlow = InputBox("Enter initial cash flow: ", "Cash Flow")
DiscRate = InputBox("Enter discount rate in decimal form: ", "Discount Rate")
Periods = InputBox("How many periods (in years) are there?", "Periods")

z = CashFlow / (1 + DiscRate) ^ Periods

MsgBox Format(z, "$0.00")

End Sub

1 个答案:

答案 0 :(得分:1)

您拥有的代码很好,只需要一个循环来创建贴现现金流。这应该做你想要的:

if(detectmob()){
    options.templatename = "loginradiuscustom_tmpl_mobile";
}else{
    options.templatename = "loginradiuscustom_tmpl";
}