在VBA中使用解决方案

时间:2016-09-30 09:05:35

标签: excel vba excel-vba

以下代码是从解算器宏生成的,然后修改了一下:

SolverOk SetCell:=flowmax, _
MaxMinVal:=1, _
ValueOf:=0, _
ByChange:= eastflow,westflow, _
Engine:=1, _
EngineDesc:="GRG Nonlinear"

SolverAdd CellRef:=error, Relation:=2, FormulaText:="0"
SolverAdd CellRef:=eastflow, Relation:=3, FormulaText:="1"
SolverAdd CellRef:=westflow, Relation:=3, FormulaText:="1"
SolverAdd CellRef:=westincon, Relation:=1, FormulaText:=concontrol
SolverAdd CellRef:=westinfluo, Relation:=1, FormulaText:=fluocontrol
SolverAdd CellRef:=westincod, Relation:=1, FormulaText:=codcontrol
SolverAdd CellRef:=westinamm, Relation:=1, FormulaText:=ammcontrol
SolverSolve

我遇到的问题是“ByChange”。我不可能引用细胞,特别是“ByChange”细胞。客户端必须看不到这些值在求解器运行时不断变化,因此变量用法。但我的语法错了。

主要问题是:如何在求解器的ByChange参数中使用用户定义的变量。

1 个答案:

答案 0 :(得分:0)

这个愚蠢的代码能帮忙吗?

Application.ScreenUpdating=False
'your solver
Application.ScreenUpdating=true