没有If语句的嵌套Else错误VBA Excel,我缺少什么?
我有以下问题。我有一个电子表格,它将SEC的数据解析成财务指标,供我评估。然而,我是一个非常糟糕的程序员,我真的不知道我在这里做错了什么。在下面的代码块中,在没有If语句的嵌套Else错误VBA Excel,我缺少什么?,excel,vba,Excel,Vba,我有以下问题。我有一个电子表格,它将SEC的数据解析成财务指标,供我评估。然而,我是一个非常糟糕的程序员,我真的不知道我在这里做错了什么。在下面的代码块中,在ElseIf lngIteratorPhi=271处,我一直得到Else而没有If错误。我已经包括了前面和下面的模块,如果它们有帮助的话。抱歉,如果我遗漏了一些明显的东西,我的大脑会在VBA应用程序中融化 ElseIf lngIteratorPhi = 270 Then 'dcf calculator EPS dblAverag
ElseIf lngIteratorPhi=271处,我一直得到Else而没有If错误。我已经包括了前面和下面的模块,如果它们有帮助的话。抱歉,如果我遗漏了一些明显的东西,我的大脑会在VBA应用程序中融化
ElseIf lngIteratorPhi = 270 Then 'dcf calculator EPS
dblAverageFCFGrowthRateOverPast10Years = dblMinGrowthRate
If IsError(Sheets("Workout").Cells(1 + lngIteratorAlpha, 105).Value) = False _
And IsEmpty(Sheets("Workout").Cells(1 + lngIteratorAlpha, 105).Value) = False _
And Sheets("Workout").Cells(1 + lngIteratorAlpha, 105).Value <> 0 Then
dblAverageFCFGrowthRateOverPast10Years = Sheets("Workout").Cells(1 + lngIteratorAlpha, 105).Value / 100
Else
dblAverageFCFGrowthRateOverPast10Years = dblMinGrowthRate
End If
If dblAverageFCFGrowthRateOverPast10Years >= 0.2 Then
dblAverageFCFGrowthRateOverPast10Years = dblMaxGrowthRate
ElseIf dblAverageEarningsGrowthRateOverPast10Years <= 0.05 Then
dblAverageFCFGrowthRateOverPast10Years = dblMinGrowthRate
Else
dblAverageFCFGrowthRateOverPast10Years = dblMinGrowthRate
End If
dblAverageFCFGrowthRateOverPast10Years = dblGrowthRateInGrowthStage
If IsError(Sheets("Workout").Cells(1 + lngIteratorAlpha, 260).Value) = False _
And IsEmpty(Sheets("Workout").Cells(1 + lngIteratorAlpha, 260).Value) = False _
And Sheets("Workout").Cells(1 + lngIteratorAlpha, 260).Value <> 0 Then
dblFCF = Sheets("Workout").Cells(1 + lngIteratorAlpha, 260).Value
End If
strGrowthPeriodCalcEqTemp = ""
strTerminalPeriodCalcEqTemp = ""
For n = 1 To intYearsOfGrowthStage
strGrowthPeriodCalcEqTemp = "((1 + " & dblGrowthRateInGrowthStage & ")^" & n & "/ (1 +" & dblDiscountRate & ")^" & n & ") +"
strGrowthPeriodCalcEq = strGrowthPeriodCalcEq & strGrowthPeriodCalcEqTemp
If n = intYearsOfGrowthStage Then
strGrowthPeriodCalcEq = Left(strGrowthPeriodCalcEq, Len(strGrowthPeriodCalcEq) - 2)
strGrowthPeriodCalcEq = strGrowthPeriodCalcEq & ")"
End If
Next n
dblGrowthPeriodCalc = Eval(strGrowthPeriodCalcEq)
For n = 1 To intYearsOfTerminalGrowth
strTerminalPeriodCalcEqTemp = "((1 + " & dblTerminalGrowthRate & ")^" & n & "/ (1 +" & dblDiscountRate & ")^" & n & ") +"
strTerminalPeriodCalcEq = strTerminalPeriodCalcEq & strTerminalPeriodCalcEqTemp
If n = intYearsOfTerminalGrowth Then
strTerminalPeriodCalcEq = Left(strTerminalPeriodCalcEq, Len(strTerminalPeriodCalcEq) - 2)
strTerminalPeriodCalcEq = strTerminalPeriodCalcEq & ")"
End If
Next n
dblTerminalPeriodCalc = Eval(strTerminalPeriodCalcEq)
dblDCFFCF = dblFCF * (dblGrowthPeriodCalc + dblTerminalPeriodCalc)
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.NumberFormat = "$???,??0.00;[red]-$???,??0.00;$???,??0.00" ' currency for under 100,000 dollars
End With
Else
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.Value = "NULL"
End With
ElseIf lngIteratorPhi = 271 Then 'dcf calculator EPS
dblAverageEarningsGrowthRateOverPast10Years = dblMinGrowthRate
If IsError(Sheets("Workout").Cells(1 + lngIteratorAlpha, 98).Value) = False _
And IsEmpty(Sheets("Workout").Cells(1 + lngIteratorAlpha, 98).Value) = False _
And Sheets("Workout").Cells(1 + lngIteratorAlpha, 98).Value <> 0 Then
dblAverageEarningsGrowthRateOverPast10Years = Sheets("Workout").Cells(1 + lngIteratorAlpha, 98).Value / 100
End If
If dblAverageEarningsGrowthRateOverPast10Years >= 0.2 Then
dblAverageEarningsGrowthRateOverPast10Years = dblMaxGrowthRate
ElseIf dblAverageEarningsGrowthRateOverPast10Years <= 0.05 Then
dblAverageEarningsGrowthRateOverPast10Years = dblMinGrowthRate
End If
dblAverageEarningsGrowthRateOverPast10Years = dblGrowthRateInGrowthStage
If IsError(Sheets("Workout").Cells(1 + lngIteratorAlpha, 11).Value) = False _
And IsEmpty(Sheets("Workout").Cells(1 + lngIteratorAlpha, 11).Value) = False _
And Sheets("Workout").Cells(1 + lngIteratorAlpha, 11).Value <> 0 Then
dblEPS = Sheets("Workout").Cells(1 + lngIteratorAlpha, 11).Value
End If
For n = 1 To intYearsOfGrowthStage
strGrowthPeriodCalcEqTemp = ""
strGrowthPeriodCalcEqTemp = "((1 + " & dblGrowthRateInGrowthStage & ")^" & n & "/ (1 +" & dblDiscountRate & ")^" & n & ") +"
strGrowthPeriodCalcEq = strGrowthPeriodCalcEq & strGrowthPeriodCalcEqTemp
If n = intYearsOfGrowthStage Then
strGrowthPeriodCalcEq = Left(strGrowthPeriodCalcEq, Len(strGrowthPeriodCalcEq) - 2)
strGrowthPeriodCalcEq = strGrowthPeriodCalcEq & ")"
End If
Next n
dblGrowthPeriodCalc = Eval(strGrowthPeriodCalcEq)
For n = 1 To intYearsOfTerminalGrowth
strTerminalPeriodCalcEqTemp = ""
strTerminalPeriodCalcEqTemp = "((1 + " & dblTerminalGrowthRate & ")^" & n & "/ (1 +" & dblDiscountRate & ")^" & n & ") +"
strTerminalPeriodCalcEq = strTerminalPeriodCalcEq & strTerminalPeriodCalcEqTemp
If n = intYearsOfTerminalGrowth Then
strTerminalPeriodCalcEq = Left(strTerminalPeriodCalcEq, Len(strTerminalPeriodCalcEq) - 2)
strTerminalPeriodCalcEq = strTerminalPeriodCalcEq & ")"
End If
Next n
dblTerminalPeriodCalc = Eval(strTerminalPeriodCalcEq)
dblDCFEPS = dblEPS * (dblGrowthPeriodCalc + dblTerminalPeriodCalc)
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.NumberFormat = "$???,??0.00;[red]-$???,??0.00;$???,??0.00" ' currency for under 100,000 dollars
End With
Else
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.Value = "NULL"
End With
ElseIf lngIteratorPhi = 273 Then
If IsError(Sheets("Workout").Cells(1 + lngIteratorAlpha, 270).Value) = False _
And IsEmpty(Sheets("Workout").Cells(1 + lngIteratorAlpha, 270).Value) = False _
And Sheets("Workout").Cells(1 + lngIteratorAlpha, 270).Value <> 0 Then
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.Value = Sheets("Workout").Cells(1 + lngIteratorAlpha, 270).Value * 0.85
.NumberFormat = "$???,??0.00;[red]-$???,??0.00;$???,??0.00" ' currency for under 100,000 dollars
End With
Else
With Sheets("Workout").Cells(1 + lngIteratorAlpha, 0 + lngIteratorPhi)
.Value = "NULL"
End With
End If
ElseIf lngIteratorPhi=270然后是“dcf计算器”
DbLaverAgefCfGrowthRateOverPost10年=dblMinGrowthRate
如果IsError(表(“训练”)单元格(1+lngIteratorAlpha,105).Value)=False_
和IsEmpty(表(“锻炼”)。单元格(1+lngIteratorAlpha,105)。值)=False_
和床单(“锻炼”)。单元格(1+lngIteratorAlpha,105)。然后值为0
DbLaverAgefCfGrowthRateOverPast10年=床单(“锻炼”).单元格(1+lngIteratorAlpha,105)。值/100
其他的
DbLaverAgefCfGrowthRateOverPost10年=dblMinGrowthRate
如果结束
如果DbLaverAgefCfGrowthRateOverst10年>=0.2,则
DbLaverAgefCfGrowthRateOverPost10年=dblMaxGrowthRate
否则,如果DBlaverageArning增长超过10年=0.2,则
DBLaverAgeeArningsGrowthRate超过10年=dblMaxGrowthRate
如果我的学习经历了10年的成长,我现在明白了,我最后还有一个额外的学习机会。标记为已解决 您的代码以else
开头,但在if
中似乎没有。如果没有if,Else在概念上是没有意义的。啊,我道歉。在最开始的时候有一个If语句,这是一个相当混乱的代码,它以lngIteratorPhi=0开始,对于lngIteratorPhi=0到500调试。打印lngIteratorPhi
,然后它会变成大量的测试用例,用于格式化这些大的数字,比如上面的和如果lngIteratorPhi=2,然后使用表单(“训练”).Cells(1+lngIteratorAlpha,0+lngIteratorPhi)”.NumberFormat=“$?,?”0.00;[红色]-$??,0.00;??,0.00;???,??0.00“'以
结尾,其他以表格(“训练”)结尾。单元格(1+lngIteratorAlpha,0+LnGiteratorOphi)。Value=“NULL”以
结尾这些块(我至少可以看到两个)似乎是孤立的,所以你的代码现在可以工作了-很棒!看起来很糟糕(无意冒犯)…请随意发布(全部!)随附对其目的的描述;评论员将帮助您使其做同样的事情,只是做得更好。@Mat'smugh谢谢!我会的。我对VBA和一般编程非常陌生。