Applies To
Scenarios Collection.
Description
Creates a new scenario and adds it to the list of scenarios available for the current worksheet. Returns a Scenario object.
Syntax
object.Add(name, changingCells, values, comment, locked, hidden)
object
Required. The Scenarios object.
name
Required. A string specifying the name for the new scenario.
changingCells
Required. A range giving the changing cells for the scenario.
values
Optional. An array containing the scenario values for the cells in changingCells. If omitted, the scenario values are assumed to be the current values in the cells of changingCells.
comment
Optional. A string specifying comment text for the scenario. When a new scenario is added, author name and date are automatically added at the beginning of the comment text.
locked
Optional. True if the scenario is locked to prevent changes. If this argument is omitted, the scenario is locked.
hidden
Optional. True if the scenario is hidden. If this argument is omitted, the scenario is not hidden.
Remarks
A scenario name must be unique; Microsoft Excel generates an error if you try to create a scenario with a name already in use.
Example
This example adds a new scenario to Sheet1.
Worksheets("Sheet1").Scenarios.Add Name:="Best Case", _ ChangingCells:=Worksheets("Sheet1").Range("A1:A4"), _ Values:=Array(23, 5, 6, 21), _ Comment:="Most favorable outcome."