简体   繁体   English

EXCEL VBA忽略规划求解更改值

[英]EXCEL VBA ignores Solver changes values

I have the following snippet of Excel VBA code to solve a minimisation problem: 我有以下Excel VBA代码片段来解决最小化问题:

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. 这是使用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). 如果我从EXCEL(使用Alt-F8)运行宏,也会发生同样的情况。 However, I have assigned the same macro to a VBA button and when I press this Excel only changes cell A9. 但是,我已经将相同的宏分配给了VBA按钮,当我按下此Excel时,仅更改了单元格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. 我尝试使用SolverReset重置问题,但这会产生一个错误,指出Excel已用尽。

Would appreciate any suggestions on how to force Excel to change all three cells, not just cell A9 将不胜感激有关如何强制Excel更改所有三个单元格(而不仅仅是A9单元格)的任何建议

Thanks! 谢谢!

This problem has been modified and updated here: 此问题已在此处修改和更新:

EXCEL VBA does not run SOLVER inside a macro invoked from a chart button EXCEL VBA不在从图表按钮调用的宏中运行SOLVER

to avoid problems with chameleon questions 避免变色龙问题的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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