Hello - Below is a section of code that I created using the Macro Recorder in Excel 2010, to perform a model calculation and then paste the results in successive rows within the model:
Sub RunSimTest()
'
' RunSimTest Macro
'
'
Range("D9").Select
ActiveCell.FormulaR1C1 = "1"
Calculate
Application.Run "RiskRibbonEvent_DeferredCommandClick"
Application.Run "RiskRefreshRibbon"
Range("O2:P2").Select
Selection.Copy
Sheets("EF Data").Select
Range("W20:X20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
End Sub
This macro performs an action that I would like to have performed repeatedly until the model reaches a stopping point. If I repeated over and over again with the Macro Recorder the only things that change in the code from iteration to iteration are noted below in red (and in the code above in red as well).
1) The "1" would increase by 1 for each loop. So the second time through it would read - ActiveCell.FormulaR1C1 = "2".
2) The paste range should be moved down one row for each loop. So the second time through it would read - Range("W21:X21").Select
Can anyone tell me of a way to change the code so that the action will repeat itself 500 times (in other words, it will stop after the red number 1 in the code is 500)?
Thank you!
Sub RunSimTest()
'
' RunSimTest Macro
'
'
Range("D9").Select
ActiveCell.FormulaR1C1 = "1"
Calculate
Application.Run "RiskRibbonEvent_DeferredCommandClick"
Application.Run "RiskRefreshRibbon"
Range("O2:P2").Select
Selection.Copy
Sheets("EF Data").Select
Range("W20:X20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
End Sub
This macro performs an action that I would like to have performed repeatedly until the model reaches a stopping point. If I repeated over and over again with the Macro Recorder the only things that change in the code from iteration to iteration are noted below in red (and in the code above in red as well).
1) The "1" would increase by 1 for each loop. So the second time through it would read - ActiveCell.FormulaR1C1 = "2".
2) The paste range should be moved down one row for each loop. So the second time through it would read - Range("W21:X21").Select
Can anyone tell me of a way to change the code so that the action will repeat itself 500 times (in other words, it will stop after the red number 1 in the code is 500)?
Thank you!