我已经记录了一个宏来在excel上运行求解器,现在需要它循环以在具有必要参数的一系列行(54至288)上运行。
我正在尝试通过更改Cols来最小化Col CQ。 CF:CJ(应设为负数) 并添加2个约束:
非常感谢您的帮助!请在下面找到代码。
SolverOk SetCell:="CQ54", MaxMinVal:=2, ValueOf:=0, ByChange:="CF54:CJ54" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="CM54", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="CQ54", Relation:=3, FormulaText:="0"
SolverOk SetCell:="CQ54", MaxMinVal:=2, ValueOf:=0, ByChange:="CF54:CJ54" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="CQ54", MaxMinVal:=2, ValueOf:=0, ByChange:="CF54:CJ54" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
答案 0 :(得分:0)
未经测试:
For n = 54 to 288
SolverReset
SolverOk SetCell:="CQ" & n, MaxMinVal:=2, ValueOf:=0, _
ByChange:="CF" & n & ":CJ" & n , Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="CM" & n, Relation:=2, FormulaText:="1"
SolverAdd CellRef:="CQ" & n, Relation:=3, FormulaText:="0"
SolverSolve
Next n