简体   繁体   中英

Excel Solver Named Ranges in VBA

Is it possible to amend the vba script so that in defining the parameters for 'Solver' I can used the 'Names' for the various ranges instead of the absolute cell references?

In the example below the various ranges are defined in the spreadsheet as;

$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"

UNTESTED

Try replacing:

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

with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM