简体   繁体   中英

EXCEL VBA ignores Solver changes values

I have the following snippet of Excel VBA code to solve a minimisation problem:

SolverOk SetCell:="$AP$13", MaxMinVal:=2, ValueOf:=0, ByChange:="$AP$9:$AP$11", Engine:=1
SolverSolve UserFinish:=True

This was created using the "record macro" menu command in Excel. If I run the problem from the menu bar using Data | Solver then Solver happily changes all three cells and completes the problem. The same happens if I run the macro from EXCEL (using Alt-F8). However, I have assigned the same macro to a VBA button and when I press this Excel only changes cell A9. I get the same issue if I change the code to

SolverOk SetCell:="$AP$13", MaxMinVal:=2, ValueOf:=0, ByChange:="$AP$10:$AP$11", Engine:=1

I tried resetting the problem using SolverReset but this produces an error saying Excel has been exhausted.

Would appreciate any suggestions on how to force Excel to change all three cells, not just cell A9

Thanks!

This problem has been modified and updated here:

EXCEL VBA does not run SOLVER inside a macro invoked from a chart button

to avoid problems with chameleon questions

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