+ Reply to Thread
Results 1 to 7 of 7

how to use Solver in Excel VBA

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    3

    how to use Solver in Excel VBA

    Hi all,

    I'm trying to use solver to minimize a cell for a least squares regression. The minimization cell is a weighted sum of squared residuals. Three variables exist that define the regression line. Another six cells define the bounds for the variables.

    I get the following error:

    Compile Error: Sub or Function not defined

    Here is the code:

    Please Login or Register  to view this content.
    Any help please?
    Last edited by mvanhelden; 08-22-2012 at 10:46 AM. Reason: Added code tags

  2. #2
    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,788

    Re: how to use Solver in Excel VBA

    Before you can use the Solver VBA functions in the Visual Basic Editor, you must establish a reference to the Solver add-in. In the Visual Basic Editor, with a module active, click References on the Tools menu, and then select Solver under Available References. If Solver does not appear under Available References, click Browse, and then open Solver.xlam in the \Program Files\Microsoft Office\Office14\Library\SOLVER subfolder.

    You also should add code tags to your macro or the moderators will be upset.

    Alf

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    3

    Smile Re: how to use Solver in Excel VBA

    Thanks Alf!

    That's a great help. I figured it was something like that. I'll try it out and post the results soon.

    All the best,

    mvanhelden

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: how to use Solver in Excel VBA

    @ mvanhelden

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). As Alf pointed out, the forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

    Also, by failing to add the code tags after their required usage was pointed out to you by Alf, you broke rule #7. And that's much more likely to "upset the moderators".

  5. #5
    Registered User
    Join Date
    08-21-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Office Professional Plus 2010
    Posts
    3

    Re: how to use Solver in Excel VBA

    didn't mean to upset anyone. just new to this and didn't understand "the rules".

    Thanks for the help, Alf.

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: how to use Solver in Excel VBA

    Nobody's upset. But you should familiarize yourself with the rules.

  7. #7
    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,788

    Re: how to use Solver in Excel VBA

    Thanks for the help, Alf.
    Glad to be of help.

    Alf

    Ps: If this solves your problem don't forget to mark your thread "solved"

    Rule #9
    and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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