0

I am trying to loop a solver command down a specific row of target cells with the ByChange range and ValueOf range also changing with each loop.

Essentially so that I don't have to do this manually down a table.

So far I have:

Sub loop_solver()

Dim i As Long

For i = 1 To 10

    SolverReset
    SolverOptions precision:=0.001

    SolverOk SetCell:=Range("S & i"), ByChange:=Range("O & i:Q & i"), _
        MaxMinVal:=3, ValueOf:=Range("T & i")

    SolverSolve UserFinish:=True

    SolverFinish KeepFinal:=1

Next

End Sub

I also need to work in a constraint that also changes cell with every loop.

Lewis Jones
  • 53
  • 1
  • 9

1 Answers1

1

Just so anyone who is interested. I got my code to work by adding a .offset as I realised you can't count the loop within a range.

Sub loop_solver()

Dim i As Long

For i = 0 To 10

   SolverReset
   SolverOptions precision:=0.001

   SolverOk SetCell:=Range($S$3).Offset(i,0), ByChange:=Range("$O$3:$Q$3").Offset(i,0), _
        MaxMinVal:=3, ValueOf:=Range("$T$3").Offset(i,0)

   SolverSolve UserFinish:=True

   SolverFinish KeepFinal:=1

Next

End Sub
Lewis Jones
  • 53
  • 1
  • 9