Hello,
I have written a simple macro to record the results of a MonteCarlo simulation. The macro copies the results from each calculation and pastes them on a "results" worksheet where eventually the results will be analyzed. This macro processes the calculation 1,000 times and I would like for the user to be unaware of the process going on behind the scenes (i.e. no screen flickering). I have used a variation of this macro before with no screen flickering but this one doesn't seem to be working. I can still see Excel pasting the results on the "results" worksheet. I have inserted the code below...any help would be much appreciated.
Thanks!
I have written a simple macro to record the results of a MonteCarlo simulation. The macro copies the results from each calculation and pastes them on a "results" worksheet where eventually the results will be analyzed. This macro processes the calculation 1,000 times and I would like for the user to be unaware of the process going on behind the scenes (i.e. no screen flickering). I have used a variation of this macro before with no screen flickering but this one doesn't seem to be working. I can still see Excel pasting the results on the "results" worksheet. I have inserted the code below...any help would be much appreciated.
Thanks!
Code:
Sub MonteCarlo()
Application.ScreenUpdating = False
Dim i, iMax As Integer
iMax = 1000
Sheet4.Range("B2:E1001").ClearContents 'Clear existing contents of results area
iMax = iMax + 1
For i = 1 To iMax 'Run the number of iterations the user specifies
Application.ScreenUpdating = False 'Turn off screen updating to speed up process
Sheet1.Calculate 'Calculate the "calculation" sheet to generate new random results
'Copy each of the imporant results and paste them on the results page
Sheet1.Range("NPV").Copy
Sheet4.Cells(i + 1, 2).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheet1.Range("IRR").Copy
Sheet4.Cells(i + 1, 3).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheet1.Range("ROI").Copy
Sheet4.Cells(i + 1, 4).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheet1.Range("Payback").Copy
Sheet4.Cells(i + 1, 5).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Next i
Application.ScreenUpdating = True 'Turn screen updating back on to allow user to see results
End Sub