简体   繁体   中英

Excel Solver and VBA: Floating point/decimal numbers in constraints get incorrectly converted to integers?

I'm running VBA scripts under both Excel 2007 and 2010 which involve a lot of optimization using the built-in Solver of Excel.

What is the correct way to specify decimal constraints like X>=0.0001 where X would be the decision variable of the problem.

SolverAdd CellRef:=cells(5,5), Relation:=3, FormulaText:="0.0001"

Or do I have to remove the quotes " " ? And does the VBA interface of Solver allow for decimal (non-integer) constraints anyway?

I'm asking, because sometimes I get the (unconfirmed) feeling that a constraint of >=0.0001 is incorrectly interpreted as >=1, which of course renders wrong results.

It would be great if somebody could clarify these issues for me.

Steve

We've found that FormulaText can really effect the final solution. We've always just used straight numbers there, no quotes:

SolverAdd CellRef:=cells(5,5), Relation:=3, FormulaText:=0.0001

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