Excel解算器在VBA中命名范围

时间:2015-05-23 21:48:01

标签: excel-vba solver vba excel

是否可以修改vba脚本,以便在定义' Solver'我可以使用'姓名'对于各种范围而不是绝对单元格引用?

在下面的示例中,各种范围在电子表格中定义为;

$A$1 ..... "obj_func"
$E$8:$E$11,$I$8:$M$11 ..... "bin_var", "qty_cut"
$C$8:$C$11 ..... "qty_used"



SolverOk SetCell:="$A$1", MaxMinVal:=2, ValueOf:=0, ByChange:= _
"$E$8:$E$11,$I$8:$M$11", Engine:=2, EngineDesc:="Simplex LP"

SolverAdd CellRef:="$C$8:$C$11", Relation:=1, FormulaText:="stock_lengths"

1 个答案:

答案 0 :(得分:0)

<强> UNTESTED

尝试更换:

SolverAdd CellRef:="$C$8:$C$11", Relation:=1, FormulaText:="stock_lengths"

使用:

SolverAdd CellRef:=Range("qty_used").Address, Relation:=1, FormulaText:="stock_lengths"