Hi all, I've posted about this VBA before, but issues keep popping up so I gotsta return
The loop works most of the time, but sometimes the loop stops adhering to the constraints. This happens at random times in the loop and sometimes doesn't happen, but it appears to be that it stops changing either the D or C value for a certain point on the loop. Sometimes it starts working at the next point, and sometimes it continues to fail. I know its not because the constraints can't be met because if I fiddle around with the values in C and D before running the loop it produces the right answers.
Any ideas regarding how to guarantee that the loop runs correctly the whole way through first time?
Thanks
Sub SolverLoop()
Dim i As Integer
For i = 5 To 32
SolverReset
SolverOK SetCell:=Cells(i, 58).Address, MaxMinVal:=3, ValueOf:=0, ByChange:="$D$" & i
SolverSolve UserFinish:=True
Next
Dim j As Integer
For j = 35 To 64
k = j - 1
SolverReset
SolverOK SetCell:=Cells(j, 64).Address, MaxMinVal:=3, ValueOf:=0, ByChange:="$D$" & j & ":$C$" & j
SolverAdd CellRef:=Cells(j, 62).Address, Relation:=2, FormulaText:="=1"
SolverAdd CellRef:=Cells(j, 63).Address, Relation:=2, FormulaText:="=1"
SolverAdd CellRef:="$C$" & j, Relation:=1, FormulaText:="$BM$" & k
SolverAdd CellRef:="$C$" & j, Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$D$" & j, Relation:=1, FormulaText:="$BN$" & k
SolverAdd CellRef:="$D$" & j, Relation:=3, FormulaText:="0"
SolverSolve UserFinish:=True
Next
End Sub
Bookmarks