Class Scenario (Excel VBA)

The class Scenario represents a scenario on a worksheet.

The main procedures of class Scenario are Delete and Scenarios.Add

For Each

Here is an example of processing the Scenario items in a collection.

Dim scns As Scenarios: Set scns = 
For Each scn In scns.Merge Source:=
	With scn
		
	End With
Next scn

Methods

These are the main methods of the Scenario class

Delete - Deletes the object.

scn.Delete

Scenarios.Add - Creates a new scenario and adds it to the list of scenarios that are available for the current worksheet.

Worksheets("Sheet1").Scenarios.Add Name:="Best Case", _ 
 ChangingCells:=Worksheets("Sheet1").Range("A1:A4"), _ 
 Values:=Array(23, 5, 6, 21), _ 
 Comment:="Most favorable outcome."

Other Methods

ChangeScenario - Changes the scenario to have a new set of changing cells and (optionally) scenario values.

Show - Shows the scenario by inserting its values on the worksheet. The affected cells are the changing cells of the scenario.

Scenarios.CreateSummary - Creates a new worksheet that contains a summary report for the scenarios on the specified worksheet.

Scenarios.Item - Returns a single object from a collection.

Scenarios.Merge - Merges the scenarios from another sheet into the Scenarios collection.

Properties

ChangingCells returns a Range object that represents the changing cells for a scenario.

Comment returns or sets a String value that represents the comment associated with the scenario.

Hidden returns or sets a Boolean value that indicates if the scenario is hidden.

Index returns a Long value that represents the index number of the object within the collection of similar objects.

Locked returns or sets a Boolean value that indicates if the object is locked.

Name returns or sets a String value representing the name of the object.

Parent returns the parent object for the specified object. Read-only.

Values returns a Variant array that contains the current values of the changing cells for the scenario.

Scenarios.Count returns a Long value that represents the number of objects in the collection.

Scenarios.Parent returns the parent object for the specified object. Read-only.