I am trying to paste values from one worksheet, called "Economic Assumptions", to another, called "Economic Simulations".
To give a little context, rows 17, 20, 23 and 26 in "Economic Assumptions" generate random numbers, which then affect what comes out in row 14. I want to copy what is in row 14 to row 3 in "Economic Simulations", starting from column B.
It is also ideal for me to do this in a loop, as I need to repeat this 1000 times (i.e. I need to copy 1000 different row 14s).
My code is as follows:
Sub Macro1()
Sheets("Economic Assumptions").Activate
For i = 1 To 1000
Range("B17:BL17") = WorksheetFunction.RandArray(1, 63)
Range("B20:BL20") = WorksheetFunction.RandArray(1, 63)
Range("B23:BL23") = WorksheetFunction.RandArray(1, 63)
Range("B26:BL26") = WorksheetFunction.RandArray(1, 63)
Sheets("Economic Simulations").Range(Cells(i + 2, 2), Cells(i + 2, 64)).Value = Sheets("Economic Assumptions").Range("B14:BL14").Value
Next i
End Sub
Everything works fine except for the line which says Sheets("Economic Simulations").Range(Cells(i + 2, 2), Cells(i + 2, 64)).Value = Sheets("Economic Assumptions").Range("B14:BL14").Value
, which gives me "application-defined or object-defined error" when run. I have tried modifying the line by changing Sheets
to Worksheets
or even Application.Worksheets
, but they all do not work.
Any suggestions as to how I can do this copy and pasting will be greatly appreciated! If it makes any difference, the range I am copying from is always fixed; it is the range I am pasting to that needs to increase by 1 row each time.