I am using Solver with the following code:
Sub Test()
SolverReset
SolverOk SetCell:="$K$7", MaxMinVal:=1, ValueOf:=0, ByChange:="$I$7:$J$7", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$G$7", Relation:=2, FormulaText:="$H$7"
SolverAdd CellRef:="$K$7", Relation:=2, FormulaText:="$B$7"
SolverSolve UserFinish:=False
SolverFinish KeepFinal:=1
End Sub
I now need to put it into a loop in order to run Solver from row 7 to row 17. I coded it as per the below but it doesn't work:
Dim i As Long
For i = 7 To 17
SolverReset
SolverOk SetCell:="$K$" & i, MaxMinVal:=1, ValueOf:=0, ByChange:="$I$ & i:$J$ & i", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$G$" & i, Relation:=2, FormulaText:="$H$" & i
SolverAdd CellRef:="$K$" & i, Relation:=2, FormulaText:="$B$" & i
SolverSolve UserFinish:=False
SolverFinish KeepFinal:=1
Next i
End sub