Scenarios.Add method (Excel)
Creates a new scenario and adds it to the list of scenarios that are available for the current worksheet.
Syntax
expression.Add (Name, ChangingCells, Values, Comment, Locked, Hidden)
expression A variable that represents a Scenarios object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
Name | Required | String | The scenario name. |
ChangingCells | Required | Variant | A Range object that refers to the changing cells for the scenario. |
Values | Optional | Variant | An array that contains the scenario values for the cells in ChangingCells. If this argument is omitted, the scenario values are assumed to be the current values in the cells in ChangingCells. |
Comment | Optional | Variant | A string that specifies comment text for the scenario. When a new scenario is added, the author's name and date are automatically added at the beginning of the comment text. |
Locked | Optional | Variant | True to lock the scenario to prevent changes. The default value is True. |
Hidden | Optional | Variant | True to hide the scenario. The default value is False. |
Return value
A Scenario object that represents the new scenario.
Remarks
A scenario name must be unique; Microsoft Excel generates an error if you try to create a scenario with a name that's 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."
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기