I'm a novice at VBA, and I'm trying to use the solver to loop through multiple times to minimize a value in column F by changing the 2 fields in column R. For testing it loops to 104, but once this works it will go to 2158 for the limit. My issue is it appears to be looping, but it is not solving (not changing the values in column R to minimize the value in column F). I'm sure this is quite simple but I'm stuck. Below is what I've muddled together. Thanks for any assistance that can be provided.
Sub solver_loop()
Worksheets("parts").Activate
Dim i As Integer
limit = 104
i = 0
Application.ScreenUpdating = True
Do Until i = limit
SolverReset
SolverOk SetCell:="$F$" & 12 + i, MaxMinVal:=2, ValueOf:="0", ByChange:="$R$ & 8 + i:$R$ & 9 + i"
SolverAdd CellRef:="$R$" & 8 + i, Relation:=1, FormulaText:="$T$9"
SolverAdd CellRef:="$R$" & 8 + i, Relation:=3, FormulaText:="$T$8"
SolverAdd CellRef:="$R$" & 9 + i, Relation:=1, FormulaText:="$T$9"
SolverAdd CellRef:="$R$" & 9 + i, Relation:=3, FormulaText:="$T$8"
SolverOk SetCell:="$F$" & 12 + i, MaxMinVal:=2, ValueOf:="0", ByChange:="$R$ & 8 + i:$R$ & 9 + i"
SolverOptions MaxTime:=40, Iterations:=1000, Precision:=0.0001, AssumeLinear:=False, StepThru:=False, Estimates:=1
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
i = i + 13
Application.StatusBar = "Progress: " & (i / 13) + 1 & " of " & (limit / 13) + 1 & " : " & Format(i / limit, "Percent")
Loop
End Sub
Bookmarks