I am not very experienced in VBA but I have a basic understanding of it. I am trying to create an optimization model where Solver generates minimum values for a set of constraints:
-Cell O40 needs to be minimized, and that value recorded and printed in a cell Kx -Cell O41 is my dynamic constraint, where it needs to be set equal to the value in cell Jx for each iteration of the solver. -Cells J40:J45 are weights which will be changing, and subject to the constraint J46=1 (where J46=SUM(J40:J45) such that the weights add up to 1)
I ran Solver once and recorded a macro and got the following output:
Sub Solve()
SolverAdd CellRef:="$J$46", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="$O$41", Relation:=2, FormulaText:="$J17"
SolverOk SetCell:="$O$40", MaxMinVal:=2, ValueOf:=0, ByChange:="$J$40:$J$45", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
End Sub
Now I need the Solver to do two things:
Write the value that is solved for in cell O40 into the cell Kx, at the end of the routine, where cell Kx corresponds to the adjoining cell Jx that determined the fixed value constraint of cell O41.
Repeat the process for the range J17:J33, changing the fixed value constraint in cell O41.
The result should be that the values in the cells K17:K33 are filled in and minimized for a given level in cells J17:J33.
I appreciate any help I can get.