Rollnation
New Member
- Joined
- Jan 17, 2017
- Messages
- 17
Novice question...
I am trying to loop Solver through a specified array of worksheets in a workbook twice. With a Copy&paste values routine in between.
Currently the routines will work if run separately but to combine them I believe I need to make the entire sub option explicit because I start to get compile errors.
Objective
1. Run will solver to to minimize values in X cells through each worksheet in array
2. Copy and paste values in through each worksheet in array
3. Run will solver to to minimize values in Y cells through each worksheet in array
I am trying to use similar code to accomplish these three tasks but am not sure how to get them to run together. Do I need to make each option explicit and change the variables?
My code:
The sheetlist array is much larger but I have condensed it here
1.
2.
3.
I am trying to loop Solver through a specified array of worksheets in a workbook twice. With a Copy&paste values routine in between.
Currently the routines will work if run separately but to combine them I believe I need to make the entire sub option explicit because I start to get compile errors.
Objective
1. Run will solver to to minimize values in X cells through each worksheet in array
2. Copy and paste values in through each worksheet in array
3. Run will solver to to minimize values in Y cells through each worksheet in array
I am trying to use similar code to accomplish these three tasks but am not sure how to get them to run together. Do I need to make each option explicit and change the variables?
My code:
The sheetlist array is much larger but I have condensed it here
1.
Code:
Sub SolverLoop()
Sheetlist = Array("Total_SanDiego", "Total_Ventura")
Worksheets(Sheetlist(i)).Activate
'Initiate smoothing constants from .1
Range("N11") = "0.1"
Range("N12") = "0.1"
Range("AI11") = "0.1"
Range("AO11") = "0.1"
Range("AZ11") = "0.1"
Range("AZ12") = "0.1"
Range("AZ13") = "0.1"
SolverReset
SolverAdd CellRef:="N11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="N12", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AI11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AO11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ12", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ13", Relation:=1, FormulaText:="=1"
SolverOk SetCell:="AZ20", MaxMinVal:=2, ValueOf:=0, ByChange:="AZ11:AZ13", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="AO20", MaxMinVal:=2, ValueOf:=0, ByChange:="AO11", Engine _
:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="AI20", MaxMinVal:=2, ValueOf:=0, ByChange:="AI11", Engine _
:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="N20", MaxMinVal:=2, ValueOf:=0, ByChange:="N11:N12", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
Next
End Sub
2.
Code:
Sub CopyPasteBacktestMape()
' CopyPasteBacktestMape Macro
' Copy and paste values of backtest results between backtest and final solver. This ensures visibility of the backtest MAPE after the final solver.
Sheetlist = Array("Total_SanDiego", "Total_Ventura")
For i = LBound(Sheetlist) To UBound(Sheetlist)
Range("I18:AZ18").Value = Range("I21:AZ21").Value
Next
End Sub
Code:
Sub SolverLoopFinal()
Sheetlist = Array("Total_SanDiego", "Total_Ventura") ', "Total_SealBeach", "Total_Ventura", "San_Diego", "Miramar", "SCI", "China_Lake", "El_Centro", "Fallon", "Lemoore", "Monterey", "SNI", "COGEN")
For i = LBound(Sheetlist) To UBound(Sheetlist)
' These locations are excluded from the solver to reduce runtime, they are included in Total_SealBeach and Total_Ventura
'"NORCO", "Fallbrook","Seal_Beach", "Port_Hueneme", "Pt_Mugu"
Worksheets(Sheetlist(i)).Activate
'Initiate smoothing constants from .1
Range("N11") = "0.1"
Range("N12") = "0.1"
Range("AI11") = "0.1"
Range("AO11") = "0.1"
Range("AZ11") = "0.1"
Range("AZ12") = "0.1"
Range("AZ13") = "0.1"
SolverReset
SolverAdd CellRef:="N11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="N12", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AI11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AO11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ11", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ12", Relation:=1, FormulaText:="=1"
SolverAdd CellRef:="AZ13", Relation:=1, FormulaText:="=1"
SolverOk SetCell:="AZ15", MaxMinVal:=2, ValueOf:=0, ByChange:="AZ11:AZ13", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="AO15", MaxMinVal:=2, ValueOf:=0, ByChange:="AO11", Engine _
:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="AI15", MaxMinVal:=2, ValueOf:=0, ByChange:="AI11", Engine _
:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverOk SetCell:="N15", MaxMinVal:=2, ValueOf:=0, ByChange:="N11:N12", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
Next
End Sub
Last edited by a moderator: