Using Solver in VBA sets calculation mode to manual

前端 未结 1 795
囚心锁ツ
囚心锁ツ 2021-01-06 08:22

In trying to help address this question, I came across some very strange behavior from Solver in VBA.

I am wondering if anyone else can reproduce it

相关标签:
1条回答
  • 2021-01-06 09:03

    I just ran your code in Excel 2010 and got the same results. If anything, it is worse in that I get the bug whether or not SolverReset is called and, furthermore, after running the code the text "Setting Up Problem..." lingers in the status bar on the bottom of Excel

    It makes perfect sense that the Solver needs to set calculation to manual with GRG Nonlinear since it is going to be evaluating the objective function by changing cells in the worksheet and wouldn't want to evaluate them until the correct input values are in place. When called from the Excel interface, the Solver cleans up after itself. Whoever put together the VBA interface must have forgotten this little detail. Its clearly a bug. Perhaps you could file a bug report at Solver.com (the website of Frontline Systems, who make the solver for Microsoft) .The workaround is of course easy enough: just put the line

    Application.Calculation = xlCalculationAutomatic
    

    at the bottom of the sub.

    0 讨论(0)
提交回复
热议问题