微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

调用目标查找子的场景分析宏

如何解决调用目标查找子的场景分析宏

我有一个场景分析宏,它计算 4 个不同场景的 NPV(每个场景都有独特的参数),其中 IRR 等于一个目标:

Sub ScenarioTable()

'Declare variables.
Dim i As Integer

'Dim InitialScenario As Integer
Dim ScenarioCount As Range
Dim rngScenariocopy As Range
Dim rngScenarioPaste As Range

'Populate variables with data from sheet.
Set InitialScenario = Range("Scenario_Switch")

'Set range variables to anchor cells on the worksheet.
Set ScenarioCount = Range("Scenario_Count")
Set rngScenariocopy = Range("Scenario_copy")
Set rngScenarioPaste = Range("Scenario_Paste")

'Start the counter at 1
i = 0

'Starting at an anchor point for each scenario number we test whether the cell is empty before continuing.
do while ScenarioCount.Offset(1,0).Errors.Item(1).Value = False
Set rngScenariocopy = Range("Scenario_copy")

'Paste output into column.
rngScenarioPaste.Offset(0,i).Value = rngScenariocopy.Value

'Call goalseek macro
Call GoalSeek.KDGoalSeek

'Input scenario number into the scenario manager.
InitialScenario.Value = i + 2
i = i + 1

Loop

'Return scenario back to original number.
InitialScenario.Value = 1

End Sub

代码输出确实为每种情况产生了 NPV,但每种情况下的 IRR 并不等于目标

我使用的目标搜索宏是:

Sub KDGoalSeek()
' Goal seeks a value using named ranges.
Application.ScreenUpdating = False


' Keyboard Shortcut: Ctrl+g

'Goal:=Range("Target") is the cell reflecting our goal value
'ChangingCell:=Range("GS_Input")the input cell that needs to adjust its value to achieve the goal
'Range("GS_Output"). is the cell that determines the changing cell i.e. the input
Range("GS_Output").GoalSeek Goal:=Range("Target"),ChangingCell:=Range("GS_Input")

Application.ScreenUpdating = True

End Sub

目标查找宏本身就是输出正确的目标 IRR,但在场景分析宏中使用时却没有。

感谢关于为什么场景分析宏没有输出目标 IRR 和相关 NPV 的帮助

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。