VBA: Runtime Error 1004 using Solver

I am new to VBA and have some problems using Solver in a macro. I assign the macro to the command button in Excel, and they all calculate fine, but an ugly error appears at the end ("Runtime Error 1004, calculating object method _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
+3
source share
2 answers

I was getting the same error in the Solver macro.

I have tried some of the things mentioned in several Excel forums. As follows from the comment, I added SolverFinishand also wrapped my entire type SetCellsto Range. I also saved the file and exited Excel.

So the trick and pop-up error disappeared for me when I returned.

+2
source

, Solver , , SolverOk VBA. MSDN, "Excel 2010 Solver Issue" , SolverReset, SolverOk, SolverReset Immediate .

SolverFinish, , , , .

+1

All Articles