VBA and Solver Help?

danby

Solid State Member
Messages
13
Hi,

I am trying to write some code in visual basic using Solver. I recorded a macro in Excel (Office XP) to create the code. However, when I run my macro, Excel says that the functions are undefined. This is the section of code that is causing me trouble:

SolverOk SetCell:="$M$2", MaxMinVal:=1, ValueOf:="0", ByChange:= _
"$G$2,$G$7,$G$10,$G$13,$G$15"
SolverAdd CellRef:="$G$2", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$G$7", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$G$10", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$G$13", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$G$15", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$G$17", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="$M$2", Relation:=2, FormulaText:="$B$20"
SolverOk SetCell:="$M$2", MaxMinVal:=1, ValueOf:="0", ByChange:= _
"$G$2,$G$7,$G$10,$G$13,$G$15"
SolverSolve

Any help at all would be greatly appreciated.

Thanks,
 
Is it just you using this workbook? Then you just need to set a reference. In the VB Editor, select the project containing this code in the Project Explorer window. On the Tools menu, select References, then scroll down the list until you find Solver, and check the box in front of it.

Now the workbook knows where to look for those functions.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top Bottom