Looping Solver VBA Question

Gleny

New Member
Joined
Mar 3, 2020
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
Greetings!
Im trying to run a solver loop that will loop through and optimize for the highest return possible on a yearly basis.
See image. What I want to do is use the previous years returns across the 7 asset classes shown to optimize the weights invested the following year in the hopes that this will provide favorable data to just simple equal weighting year after year.

The core of what I want to loop is below.
I4 is the starting value id like to optimize and then Id like to take the value in I5 and copy and paste the value alone into I5
I'd like the loop to then go to I5 and optimize based on the same constraints below and then copy and the values of I6 into I6...and so on until the referenced cell contains no value.

I cant quite figure out how to get the loop to work so im simply posting the optimizer code I know will work...
VBA Code:
Sub Solver_Final()
'
' Solver_Final Macro
'
' Keyboard Shortcut: Ctrl+Shift+O
'
        SolverReset
        SolverAdd CellRef:="$I$1", Relation:=2, FormulaText:="1"
        SolverAdd CellRef:="$B$1:$H$1", Relation:=3, FormulaText:=".1"
        SolverOk SetCell:="[COLOR=rgb(97, 189, 109)][B]I4[/B][/COLOR]", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$1:$H$1", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
        SolverSolve True
End Sub

Let me know if further clarification is needed.
Example.PNG
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,868
Messages
6,181,482
Members
453,046
Latest member
Excelvbaexpert

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top