MonteCarlo Simulation VBA... Help cleaning the code to only a certain WS in this WB

Rollnation

New Member
Joined
Jan 17, 2017
Messages
17
I have created some VBA to quickly run a monte carlo simulation of forecast errors to create prediction intervals for my forecasts.
The VBA is simply 1000 iterations of simulated forecast errors.

Question: What is the best way to ensure the VBA will run only on WS "MonteCarlo" in this workbook?
Also, this was a recorded macro that I cleaned up a bit but still needs work...

Sub Monte_Carlo()


' Monte_Carlo Macro


' Keyboard Shortcut: Ctrl+m




For i = 1 To 1000


Columns("P:P").Select
Selection.Insert Shift:=xlToRight
Range("L3:L127").Copy
Range("P3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("Q3").Select
Application.CutCopyMode = False

Next i


ActiveCell.FormulaR1C1 = "=IFERROR(PERCENTILE.EXC(RC[2]:RC[1088],0.975),"""")"
Selection.AutoFill Destination:=Range("N3:N127"), Type:=xlFillDefault
Range("N3:N127").Select
ActiveWindow.SmallScroll Down:=-135
Range("O3").Select
ActiveCell.FormulaR1C1 = "=IFERROR(PERCENTILE.EXC(RC[4]:RC[1090],0.025),"""")"
Selection.AutoFill Destination:=Range("M3:M127"), Type:=xlFillDefault
Range("M3:M127").Select


End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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