Solver in macro not work

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I've created a macro by a Solver operation. This is a recorded VB:
-------------------------------------------
Sub Macro15()
'
' Macro15 Macro
'
' Keyboard Shortcut: Ctrl+a
'
SolverOk SetCell:="$H$14", MaxMinVal:=3, ValueOf:="0", ByChange:="$G$14"
SolverAdd CellRef:="$G$14", Relation:=3, FormulaText:="$C$12"
SolverOk SetCell:="$H$14", MaxMinVal:=3, ValueOf:="0", ByChange:="$G$14"
SolverDelete CellRef:="$G$10", Relation:=3, FormulaText:="$C$12"
SolverOk SetCell:="$H$14", MaxMinVal:=3, ValueOf:="0", ByChange:="$G$14"
SolverSolve
ActiveCell.Offset(-2, 0).Range("A1").Select
End Sub

When I tried to run the macro, it did not work:

Compile error:
Sub or Function not defined

And seems it indicates that the SolverOk is not a recognizeable definition.
I'm using MS 2007. The company just install it lately.

The program is now modified to the following by referring to the MS website:

Sub Macro15()
'
' Macro15 Macro
'
' Keyboard Shortcut: Ctrl+a
'
SolverOk SetCell:="$H$14", MaxMinVal:=3, ValueOf:="0", ByChange:="$G$14"
SolverAdd CellRef:="$G$14", Relation:=3, FormulaText:="$C$12"
SolverSolve UserFinish:=True
End Sub

It still does not work and indicates the same problem.

Can anyone help?
 
Before you can use Solver functions in VBA, you must establish a reference to
the Solver add-in. Until you have established the reference, all of the
Solver commands will generate a compiler error (SolverOK was just the first
one it found in your code). In the Visual Basic Editor, with a module active,
click
References on the Tools menu, and then select the Solver.xlam check box under
Available References. If Solver.xlam does not appear under Available
References, click Browse and open Solver.xlam in the \office12\library\Solver
subfolder. If you have already installed the Solver add-in in Excel, you will
probably see it listed under Available References.

Hope this helps,

Hutch
 
Back
Top