piercebrosnan
New Member
- Joined
- Jun 19, 2013
- Messages
- 4
Hello,
I am trying to develop a monte carlo simulation that creates a data table based on the number of simulations stated. For each iteration done I would like excel to copy a specified column range between B10 to B1010 in one worksheet named "Dataset" and value paste these column values in a separate worksheet named "Simulation" in a row range say B10:B1010 in the Simulation worksheet before it goes on to the next iteration to generate another set of random numbers to perform the same task but now pasting the next iteration in a column next to the previously generated values in Simulation tab. After n iterations, excel should have a unique column of randomly generated numbers for that range.
I have tried the code below but keeping getting the top row of values repeated in each column.
Could you please assist me? This was also posted on Monte Carlo simulation - cut and paste values into separate worksheet
Thanks in advance. This is the code I tried but not getting the results I am looking for.
I am trying to develop a monte carlo simulation that creates a data table based on the number of simulations stated. For each iteration done I would like excel to copy a specified column range between B10 to B1010 in one worksheet named "Dataset" and value paste these column values in a separate worksheet named "Simulation" in a row range say B10:B1010 in the Simulation worksheet before it goes on to the next iteration to generate another set of random numbers to perform the same task but now pasting the next iteration in a column next to the previously generated values in Simulation tab. After n iterations, excel should have a unique column of randomly generated numbers for that range.
I have tried the code below but keeping getting the top row of values repeated in each column.
Could you please assist me? This was also posted on Monte Carlo simulation - cut and paste values into separate worksheet
Thanks in advance. This is the code I tried but not getting the results I am looking for.
Code:
Sub run() Dim iter As Long, r As Long, NoCols As Long Dim i As Double Dim myRange As Range 'Start real macro 'loop through for our count of iterations iter = ThisWorkbook.Sheets("Dataset").Range("D5") For i = 1 To iter Application.Calculate ThisWorkbook.Sheets("Dataset").Cells(55, 13) = ThisWorkbook.Sheets("Dataset").Range("BC11") Next i With Sheets("Dataset") Set myRange = .Range("B10:B1010", .Range("B10:B1010").End(xlToRight)) NoCols = myRange.Columns.Count End With Application.ScreenUpdating = False For r = 2 To 2 + iter - 1 myRange.Calculate Sheets("Simulation").Cells(r, "D").Resize(, NoCols).Value = myRange.Value Next r Application.ScreenUpdating = True End Sub