R
redbird
I wrote a macro so I can use Solver by hitting a button and having the macro
pick up the appropriate information from the worksheet rather than going
through the Tools|Solver menu item and entering the data manually. When I
load the worksheet and hit the "solver" button, I get the following
Microsoft Excel error message: "Solver: An unexpected internal error
occurred, or available memory was exhausted." However, if I run Solver using
Tools|Solver, update the worksheet, and THEN push my macro button (after
having run Solver once from the menu) it works fine! Is there a way to get
the macro to work the FIRST time without going through the menu once?
Windows XP Professional SP2, Excel 2003
In VBA editor, Tools | References, SOLVER is checked
Range names defined:
LastCalc: "=OFFSET(Sheet1!$G$3,COUNTA(Sheet1!$G:$G)-1,0,1,1)" <-- This is
the "Target" Cell
LastActual: "=OFFSET(Sheet1!$B$3,COUNTA(Sheet1!$B:$B)-2,0,1,1)" <-- This is
the "Equal to Value" Cell
InterestRate: "=Sheet1!$G$3" <-- This is the "By Changing" Cell
VBA macro:
Private Sub CalcInterestButton_Click()
SolverReset
SolverOptions Precision:=0.00001
SolverOK SetCell:=Range("LastCalc"), _
MaxMinVal:=3, _
ValueOf:=Range("LastActual").Value, _
ByChange:=Range("InterestRate")
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
End Sub
pick up the appropriate information from the worksheet rather than going
through the Tools|Solver menu item and entering the data manually. When I
load the worksheet and hit the "solver" button, I get the following
Microsoft Excel error message: "Solver: An unexpected internal error
occurred, or available memory was exhausted." However, if I run Solver using
Tools|Solver, update the worksheet, and THEN push my macro button (after
having run Solver once from the menu) it works fine! Is there a way to get
the macro to work the FIRST time without going through the menu once?
Windows XP Professional SP2, Excel 2003
In VBA editor, Tools | References, SOLVER is checked
Range names defined:
LastCalc: "=OFFSET(Sheet1!$G$3,COUNTA(Sheet1!$G:$G)-1,0,1,1)" <-- This is
the "Target" Cell
LastActual: "=OFFSET(Sheet1!$B$3,COUNTA(Sheet1!$B:$B)-2,0,1,1)" <-- This is
the "Equal to Value" Cell
InterestRate: "=Sheet1!$G$3" <-- This is the "By Changing" Cell
VBA macro:
Private Sub CalcInterestButton_Click()
SolverReset
SolverOptions Precision:=0.00001
SolverOK SetCell:=Range("LastCalc"), _
MaxMinVal:=3, _
ValueOf:=Range("LastActual").Value, _
ByChange:=Range("InterestRate")
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
End Sub