Macro to Show Excel ScenarioYou can use Excel Scenarios to store several versions of the data in a worksheet. To make Scenarios easier to use, see how to use a macro to automatically show a Scenario, when you select its name from a drop down list on the worksheet. Tip: To show Scenarios without a macro, see the steps to put the Scenario command on the Excel Ribbon. |
Create Drop Down List of ScenariosIn this example, there are two scenarios, with budget amounts for the Marketing Department, and the Finance Department. For each scenario, there are inputs for 3 changing cells:
This example is based on the Excel Scenarios created in the Excel Scenarios Create and Show tutorial. The video in the next section shows how those scenarios were created, if you'd like to see the steps. Video: Set Up Excel ScenariosTo see the steps for setting up the Scenarios, and showing them manually, please watch this short video tutorial. Written steps are in the Excel Scenarios Create and Show tutorial. |
View Scenario - ManuallyTo view a Scenario, you can use built-in commands on the Excel Ribbon. Those steps are listed below, and in the next section, you'll see how make it easier, by using a Scenario macro. To change to a different scenario, follow these steps:
To show a Scenario, follow the steps below:
|
View Scenario - MacroTo make it easier to switch between Scenarios, you can create a drop down list of Scenarios, and use event code to show the selected Scenario. In the sections below, there are instructions for the four steps:
Step 1: Create a list of ScenariosFollow these steps to add a new worksheet, and make a list of Scenarios
Step 2) Name list of ScenariosThe list will be easier to maintain if it's a dynamic named range. With this type of named range, it will adjust automatically if you add or remove Scenario names. To create the named range follow these steps:
5. Click OK |
Step 3) Create Drop Down listThe next step is to create a drop down list of Scenarios on the budget sheet. Then, instead of using the Scenario Manager, you'll be able to select a Scenario name right on the worksheet. To create the drop down list, follow these steps
Now, when you click on cell B1, a drop down arrow appears at the right side. You can click the arrow, and select a Scenario name, but nothing will change in the Budget values yet. You'll add the VBA code in the next section. |
Save the WorkbookNow that you've added VBA code to the workbook, you'll need to save the file in a macro-enabled format. To do that, follow these steps:
Note: When opening the workbook, you will have to enable macros in order to use this code. Download the Sample FileShow Scenario Macro: Click this link to get the completed Excel Automatically Show Scenarios Macro workbook. The zipped file is in xlsm format, and contains macros. Be sure to enable macros when you open the workbook, if you want to test the code. More Tutorials |
Last updated: August 19, 2022 8:54 PM