Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default Using Solver in VBA

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


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default Using Solver in VBA

You need to reference Solver in the VBE
The quote below is taken from
http://www.vertex42.com/ExcelArticle...-examples.html

Before the macro will work, a reference to the Solver VBA add-in functions
must be added.

Adding the Solver Reference:
a.. Step 1: Edit the macro you just created (Tools Macro Macros... or
Alt+F8). This will open up Visual Basic. You can also press Alt+F11 to open
up VBA.
b.. Step 2: Add the Solver reference in visual basic (Tools
References..., then make sure that SOLVER is checked).
The VBA code for the Solver macro that was recorded for Example 2 is shown
below.

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"redbird" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solver Richard4926 Excel Discussion (Misc queries) 4 December 17th 07 08:28 PM
Solver Randy Excel Discussion (Misc queries) 1 January 21st 07 04:36 PM
Interesting Solver problem (Solver encounters an error) MrShorty Excel Discussion (Misc queries) 3 December 22nd 05 10:52 PM
Solver Saxman Excel Discussion (Misc queries) 2 November 3rd 05 12:41 PM
solver bmur Excel Discussion (Misc queries) 1 April 18th 05 08:08 PM


All times are GMT +1. The time now is 06:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"