Hi guys I am creating a model for a uni assignment. Basically this macro needs to create 50 portfolios of assets and copy and paste their information to my table. All I want to do is use a constraint as the 'min' that starts in H2 and ends in BE2, this constraint is used against the portfolio returns box I have set up, it pumps out the numbers and it then needs to copy and paste this numbers to the respective columns for each portfolio (1-50).
All I need help with is creating this loop and referencing the range used for the constraint and copy and paste values against the count period.
Here is my code;
Sub EfficientFrontier()
'
' EfficientFrontier Macro
' Calculates the efficient frontier from the given data set and minimum variance & optimal portfolios.
'
' Keyboard Shortcut: Ctrl+k
'
For Count = 8 To 58
Set curCell = Worksheets("Data").Cells(2, Counter)
SolverOk SetCell:="$C$27", MaxMinVal:=2, ValueOf:="0", ByChange:="$C$20:$E$20"
SolverAdd CellRef:="$F$20", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="$C$27", Relation:=2, FormulaText:="Data.Cells(2, Counter)"
SolverOk SetCell:="$C$27", MaxMinVal:=2, ValueOf:="0", ByChange:="$C$20:$E$20"
SolverSolve True
Range("$C$28:$C$29").Select
Selection.Copy
Range("Data.Cells(3, Counter):Data.Cells(4, Counter)").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("$A$22:$A$24").Select
Application.CutCopyMode = False
Selection.Copy
Range("Data.Cells(5, Counter):Data.Cells(7, Counter)").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next Count
End Sub
Thanks for your time!
Bookmarks