Creating Sheets that Calculate

Pwnzrvanhax

New Member
Joined
Apr 19, 2017
Messages
1
Hello guys,

I'm new to the forum and not particularily well versed in VBA so please bear with me. I'm making a scenario analysis of costs for different investments. I'm comparing the as-is (current) situation with several scenarios. I start with a sheet called "as-is" and then create scenarios to compare using a macro. Currently the way I have it set up is that a text box pops up and asks how many scenarios to analyze. Lets say 3 for this example, it will then make 3 "Scenario" sheets (numbered Scenario-1, Scenario-2 and Scenario-3) and 3 "cost comparison" sheets (numbered Scenario-1, Scenario-2 and Scnario-3). The "Scenario" sheet would be where the user inputs all the data for each investment option available. The "Cost Comparison" sheet should only calculate the difference between the "Scenario" sheets and the "as-is" sheet. All sheets have the exact same layout and formating.

I have managed to get the code to create the sheets thus far but have not figured out how to alter the formulas in the "cost Comparison" sheet to calculate the difference yet. The incomplete code is at the end of this post. At then end I need the code to do the following:

1) Create the "Scenario" sheets and "Cost Comparison" sheets (as described above)
2) Change all the formulas in the "Cost Comparison" sheets I just created to compare each newly created "scenario" sheet to the "as-is" sheet. (basically "Scenario" minus "as-is" to calculate delta). To elaborate this means, "Cost Comparison-1" will be "Scenario-1" minus "as-is"; "Cost Comparison -2" will be "Scenario-2" minus "as-is" and so forth.

3) maintain the formatting of the other sheets

Thanks in advance!


<code>
Code:
[/FONT]
[FONT=Verdana]Sub CreateScenariosandComparison()[/FONT]
[FONT=Verdana]'Create multiple scenario worksheets for analysis based on how many scenarios you wish to compare[/FONT]
[FONT=Verdana]    Dim I As Long[/FONT]
[FONT=Verdana]    Dim xNumber As Integer[/FONT]
[FONT=Verdana]    Dim xName As String[/FONT]
[FONT=Verdana]    Dim xActiveSheet As Worksheet[/FONT]
[FONT=Verdana]    On Error Resume Next[/FONT]
[FONT=Verdana]    Application.ScreenUpdating = False[/FONT]
[FONT=Verdana]    Set xActiveSheet = ActiveSheet[/FONT]
[FONT=Verdana]    xNumber = InputBox("Enter number of scenarios you wish to compare the As-is situation to")[/FONT]
[FONT=Verdana]    For I = 1 To xNumber[/FONT]
[FONT=Verdana]        xName = ActiveSheet.Name[/FONT]
[FONT=Verdana]        xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)[/FONT]
[FONT=Verdana]        ActiveSheet.Name = "Cost Comparison-" & I[/FONT]
[FONT=Verdana]    Next[/FONT]
[FONT=Verdana]    xActiveSheet.Activate[/FONT]
[FONT=Verdana]    Application.ScreenUpdating = True    [/FONT]
[FONT=Verdana]    On Error Resume Next[/FONT]
[FONT=Verdana]    Application.ScreenUpdating = False[/FONT]
[FONT=Verdana]    Set xActiveSheet = ActiveSheet[/FONT]
[FONT=Verdana]    For I = 1 To xNumber[/FONT]
[FONT=Verdana]        xName = ActiveSheet.Name[/FONT]
[FONT=Verdana]        xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName)[/FONT]
[FONT=Verdana]        ActiveSheet.Name = "Scenario-" & I[/FONT]
[FONT=Verdana]    Next[/FONT]
[FONT=Verdana]    xActiveSheet.Activate[/FONT]
[FONT=Verdana]    Application.ScreenUpdating = True[/FONT]
[FONT=Verdana]End Sub[/FONT]
[FONT=Verdana]
</code>
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top