Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this Solver macro?

Status
Not open for further replies.

MeGustaXL

Technical User
Aug 6, 2003
1,055
GB
Code:
 Range("C2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]"
    Range("F3").Select
    [red]SolverOk SetCell:="$I$2", MaxMinVal:=2, ValueOf:="0", ByChange:="$C$2,$D$2"[/red]
    SolverSolve userfinish:=True

It falls over at the SolverOk bit with "Compile Error: Can't find project or library"

XL2K7, Solver Add-In is installed.

Chris

So you ride yourselves over the fields,
and you make all your animal deals,
and your wise men don't know how it feels...

Ian Anderson
 
Have you added a reference to 'SOLVER' (for vba project)?

combo
 
Yes

Chris

So you ride yourselves over the fields,
and you make all your animal deals,
and your wise men don't know how it feels...

Ian Anderson
 
Aha!

This macro was recorded in XL2K3, but I'm trying to run it in 2K7 - how should I amand it to work?

The Reference is to SOLVER.XLA, but in 2K7 it's called SOLVER.XLAM of course. How do I change the reference?
 


Why not record it in 2007?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip!

Errr... I'm dumb and can't make either the Record Macro button or the Analysis tab show up.

Record Macro is greyed out [flame] Darn I hate Office 2007!!!

Chris

So you ride yourselves over the fields,
and you make all your animal deals,
and your wise men don't know how it feels...

Ian Anderson
 
Right, I've solved my PICNIC [wink] and got Solver up on the Analysis tab.

Recorded a new macro doing the same thing, and it works whilst recording, but dies when I run in from the Macros tab or assign it to a button!

I think it's that old SOLVER.XLA reference, but I don't know how to remove it, or put the correct reference in [sad]

Chris

So you ride yourselves over the fields,
and you make all your animal deals,
and your wise men don't know how it feels...

Ian Anderson
 
Praise De Lard! I have found it - under Tools, References, uncheck SOLVER Not Found, check SOLVER.

Click button, runs perfick [2thumbsup]

I don't know how it works, but every time I post a question on TT, if Skip even registers slight interest, I seem to go on and find the answer myself - Yaayy!

 
The vba code works when the vba project has a reference to SOLVER library (in older excel versions it's in 'solver.xla' file. It has nothing to do with solver add-in installation via excel interface, has to be done separately in VBE.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top