Scenario Object and the Scenarios Collection Example

Sub GetBestScenario() Dim oScen As Scenario Dim oBestScen As Scenario Dim dBestSoFar As Double 'Loop through the scenarios in the sheet For Each oScen In ActiveSheet.Scenarios 'Show the secnario oScen.Show

'Is it better?

If Range("Result").Value > dBestSoFar Then dBestSoFar = Range("Result").Value

'Yes - remember it Set oBestScen = oScen End If Next

'Show the best scenario oBestScen.Show

MsgBox "The best scenario is " & oBestScen.Name End Sub

0 0

Post a comment