Sub or Function not defined


  • I came accross a strange problem. I tried to record a macro where I used Solver.

    After I tried to run it, I was given an error message:


    Compile Error:

    Sub or Function not defined.


    The function where VBA stops is "SolverOK".

    It is not a macro that I coded, I recorded it in the excell sheet.


    Thanks for any advice.





    Code that was generated is obviously correct:


    Sub solver()
    ' solver Macro
    ' Macro recorded 26/07/2007 by Z05041K
        SolverOk SetCell:="$B$115", MaxMinVal:=3, ValueOf:="0", ByChange:="$B$91"
    End Sub

    jeudi 26 juillet 2007 09:27


Toutes les réponses

  • Hi,

    You need to include a reference to SOLVER.XLA
    With VBE use menu Tools > References. Check the Solver reference.

    • Proposé comme réponse ryguy72 samedi 9 août 2014 14:28
    • Marqué comme réponse danishaniModerator mardi 16 septembre 2014 05:30
    jeudi 26 juillet 2007 18:10
  • I have the same problem.


    OK, found this in VB Help


    SolverOk Function


    Defines a basic Solver model. Equivalent to clicking Solver on the Tools menu and then specifying options in the Solver Parameters dialog box.

    Before you use this function, you must establish a reference to the Solver add-in. With a Visual Basic module active, click References on the Tools menu, and then select the Solver.xla check box under Available References. If Solver.xla doesn't appear under Available References, click Browse and open Solver.xla in the \Office\Library\Solver\ subfolder.


    The problem is when I click Tools on the menu bar, "references" is greyed out. Went back and made sure I had all the Office modules installed and still can't get to references.


    What now???

    samedi 14 juin 2008 01:52
  • make sure u hit the stop button b4 u go into tools and references.

    if the error is highlighted, the references part will be greyed out...


    • Proposé comme réponse Psalm3_3 mercredi 22 février 2012 18:02
    samedi 14 juin 2008 07:05
  • Thank you very much. That fixed the problem.


    lundi 16 juin 2008 18:10
  • Thanks so much. Very Helpful!!
    mercredi 11 mai 2011 02:15
  • Thanks, very helpful.

    I have just started learning macro and this was something i was looking for.

    jeudi 7 août 2014 16:49
  • I use Office 2016 and also had a problem finding solver check box in the References.  The key is not to go down the list alphabetically.  The solver check box is the 7th check box from the top.  I also found the following root to the .dll file:

    Program Files>Microsoft Office>root>Office16.Library>SOLVER

    lundi 24 août 2015 22:40