This module runs solver twice for each row in a table (B50:L177) to determine the maximized values of e1 and e2. Solver works great, and the solver results
are being successfully input into cells via:
RWtop.Offset(i, 7) = e1.Value
RWtop.Offset(i, 8) = e2.Value
But the rest of the loop does not work! Everything after:
'fill out results table with results
does not work, even though the loops complete solver twice for all of i to 126 loops. Thoughts?
are being successfully input into cells via:
RWtop.Offset(i, 7) = e1.Value
RWtop.Offset(i, 8) = e2.Value
But the rest of the loop does not work! Everything after:
'fill out results table with results
does not work, even though the loops complete solver twice for all of i to 126 loops. Thoughts?
Code:
Sub SolveThru()
Dim i As Integer
Dim ratioM As Double
Dim caseM As Double
Dim ratioV As Double
Dim caseV As Double
Dim roomwidth As Range
Dim sharing As Range
Dim spacing As Range
Dim Mratioresult As Range
Dim Mcaseresult As Range
Dim Vratioresult As Range
Dim Vcaseresult As Range
Dim RWtop As Range
Dim e1 As Range
Dim e2 As Range
Dim span As Range
Worksheets("Calcs").Activate
Set roomwidth = Range("F2")
Set sharing = Range("sharing")
Set spacing = Range("a")
Set Mratioresult = Range("N324")
Set Mcaseresult = Range("O324")
Set Vratioresult = Range("N325")
Set Vcaseresult = Range("O325")
Set RWtop = Range("B50")
Set span = Range("L")
Set e1 = Range("F27")
Set e2 = Range("F33")
For i = 1 To 126
'set input cells from B51:D176
roomwidth = RWtop.Offset(i, 0)
sharing = RWtop.Offset(i, 1)
spacing = RWtop.Offset(i, 2)
SolverOptions Precision = 0.05
SolverOptions Convergence = 0.05
'solve for e1
SolverOk SetCell:="$H$27", MaxMinVal:=1, ValueOf:=0, ByChange:="$F$27", Engine _
:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$F$27", Relation:=1, FormulaText:="emax"
SolverAdd CellRef:="$F$27", Relation:=3, FormulaText:="0"
SolverSolve True
RWtop.Offset(i, 7) = e1.Value
'solve for e1
SolverOk SetCell:="$H$33", MaxMinVal:=1, ValueOf:=0, ByChange:="$F$33", Engine _
:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$F$33", Relation:=1, FormulaText:="emax"
SolverAdd CellRef:="$F$33", Relation:=3, FormulaText:="0"
SolverSolve True
RWtop.Offset(i, 8) = e2.Value
'fill out results table with results
RWtop.Offset(i, 3) = Mratioresult.Value
RWtop.Offset(i, 4) = Mcaseresult.Value
RWtop.Offset(i, 5) = Vratioresult.Value
RWtop.Offset(i, 6) = Vcaseresult.Value
RWtop.Offset(i, 9) = e1 / span
RWtop.Offset(i, 10) = e2 / span
Next i
End Sub