VBA:使用规划求解的运行时错误1004 [英] VBA: Runtime error 1004 using Solver

查看:423
本文介绍了VBA:使用规划求解的运行时错误1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,在宏中使用规划求解时遇到了一些麻烦.我正在为Excel中的命令按钮分配一个宏,它们可以完美地计算所有内容,但最后也会显示一个丑陋的错误(运行时错误1004,对象_application的方法计算失败").

I'm new to VBA, and have some trouble with using the Solver in a macro. I'm assigning a macro to a command button in Excel, and they calculate everything perfectly, but an ugly error shows up as well at the end ("Runtime error 1004, method calculation of object _application failed").

Sub serieus1()
'
' serieus1 Macro
'  

'
    SolverReset
    SolverAdd CellRef:="$R$15", Relation:=2, FormulaText:="1"
    SolverAdd CellRef:="$L$18", Relation:=2, FormulaText:="$B$3"
    SolverOk SetCell:="$L$19", MaxMinVal:=2, ValueOf:=0, ByChange:="$L$15:$Q$15", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverSolve

End Sub

推荐答案

我在Solver宏中遇到了相同的错误.

I was getting the same error in my Solver macro.

我尝试了一些Excel论坛中提到的一些事情.就像评论所暗示的那样,我确实添加了SolverFinish,并且还包装了我所有的SetCellsRange类型.我还保存了文件并退出了Excel.

I tried some of the things mentioned in several Excel forums. As the comment suggests, I did add SolverFinish, and also wrapped all my SetCells to of Range type. I also saved the file and exited out of Excel.

做到了这一点,当我重新进入时,弹出错误对我消失了.

That did the trick and the pop-up error vanished for me when I got back in.

这篇关于VBA:使用规划求解的运行时错误1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆