VBA looped solver solves, but rest of loop doesn't work

Ligiea

New Member
Joined
Aug 15, 2005
Messages
9
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?

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
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It actually did work, but it didn't show the cell updates for the commands after the comment 'fill out results table with results
Half an hour later after the loop got close to finished the cell values started to update on the screen. I've since learned that for solver-heavy routines like this one to turn off screen updating.
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top