Closed Thread
Results 1 to 8 of 8

Compile error: Sub or Function not defined

  1. #1
    Registered User
    Join Date
    06-18-2010
    Location
    Geraldton, Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Compile error: Sub or Function not defined

    I've started to record a simple macro to automate the use of Solver however the macro will not run due to the error message "Compile error: Sub or Function not defined" (see attached). The macro doesn't start and stops with the first line highlighted "SolverReset". Other macros with similar use of Solver do not have a problem. Appreciate any help regarding this problem.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Nanga; 06-20-2010 at 04:38 PM. Reason: Added code text

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Compile error: Sub or Function not defined

    Why supply a Word.doc for an excel problem?

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Compile error: Sub or Function not defined

    Did you set a reference to Solver?

    Extract from microsoft support:

    [I]To reference the Microsoft Excel Solver add-in for macros in your workbook, use the following steps:
    Open your workbook.
    On the Tools menu, point to Macro, and then click Visual Basic Editor.
    On the Tools menu, click References.
    In the Available References list, click to select the Solver.xls check box, and then click OK.

    Note If you do not see Solver.xls in the Available References list, click Browse. In the Add Reference dialog box, locate and select the Solver.xla file, and then click Open. The Solver.xla file is typically found in the C:\Program Files\Microsoft Office\Office\Library\Solver subfolder.
    You are now ready to use the Microsoft Excel Solver functions in a VBA macro./I]

    HTH Alf

  4. #4
    Registered User
    Join Date
    06-18-2010
    Location
    Geraldton, Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Compile error: Sub or Function not defined

    Thanks Alf. Ticking the Solver box in the VBA References list fixed the problem. When this is done a References folder is displayed in the VBA Project Explorer window which contains the reference to Solver.XLA. Appreciate your help.

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Compile error: Sub or Function not defined

    Glad to be of help. Don't forget to mark your question "Solved" and if you want to give me a pat on the back click on the scale icon in my post and give a rating to my answer.

    Alf

  6. #6
    Registered User
    Join Date
    06-18-2010
    Location
    Geraldton, Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Compile error: Sub or Function not defined

    OK. Thread has been marked Solved and I gave you the thumbs up. Cheers.

  7. #7
    Registered User
    Join Date
    12-23-2011
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Question Re: Compile error: Sub or Function not defined

    @Alf
    Alf, I am having a similar problem, except Excel does not recognize the "SolverOk" nomenclature (it's highlighted in yellow). I tried checking my references in the VBA editor, but "References" is grayed out so I can't even get into it. Any thoughts?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Compile error: Sub or Function not defined

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1