Consulting

Results 1 to 7 of 7

Thread: Solved: Calling the Solver from VBA

  1. #1

    Solved: Calling the Solver from VBA

    Alright. I have a super simple Solver example in the attached workbook. I am solving the Equation 4*X=8.

    I have the initial guess of X = 1 in cell A2 and I have Cell B2 = 4*A2.

    I turned on the Macro recorder and solved the equation. I did not use any of the options. This is just a 'benchmark' to get things going. The following code was generated:
    [VBA]Option Explicit
    Sub Solver1()
    '
    ' Solver1 Macro
    ' Macro recorded 12/7/2009 by Saladsamurai


    SolverOk SetCell:="$B$2", MaxMinVal:=3, ValueOf:="8", ByChange:="$A$2"
    SolverSolve
    End Sub
    [/VBA]

    After viewing the code, I went back and changed the value of A2 (the initial guess) back to 1. I then went into the VBE and clicked on the button.

    I get the error message:



    Could someone explain to me what I am missing?

    Thanks,
    Casey

    EDIT: WrkBk attached
    Last edited by Saladsamurai; 12-07-2009 at 10:52 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to set a reference to SOLVER in the VBIDE.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    You need to set a reference to SOLVER in the VBIDE.
    Ok then Honestly, I have no idea what that means. What does 'setting a reference in the VBIDE' entail?

    Thank!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Go to the VBIDE (Alt-F11)

    Look for the menu bar at the top of the window, there should be an item called Tools on that menu bar

    Navigate your mouse over Tools and click it

    The first item in that menu should be References, move your mouse over that and click it

    You will see a check listbox, scroll down that list until you find an entry entitled SOLVER, then move your mouse over the checkbox square and click it (You should see a tick mark appear)

    Exit out
    Last edited by Bob Phillips; 12-07-2009 at 12:17 PM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    In the Visual Basic Intergrated Development Environment (VBIDE),
    where the VBA (Macro) code is.
    Menu option:
    Tools > References
    In the Available References, tick SOLVER
    Then OK

  6. #6
    xld, thank you for your painfully explicit instructions. Unfortunately (for me of course), I do not see SOLVER as one of the available references. I have the SOLVER as an add-in (obviously), so I am not sure what the next step is.

  7. #7
    Ok! I found it: Tools->References->Browse->C:\Program Files\Microsoft Office\OFFICE11\Library\SOLVER

    For excel 2003

Posting Permissions

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