+ Reply to Thread
Results 1 to 7 of 7

error while using solver in VBA

  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Bakersfield, CA
    MS-Off Ver
    Excel 2003
    Posts
    37

    error while using solver in VBA

    I recorded a macro using 'Solver'. When I try to run it, I get a message"Complie Error: Sub or Function not defined". Can anyone help me?
    Heres the code:
    Sub Macro1()
    SolverOk SetCell:="$R$4", MaxMinVal:=3, ValueOf:="4275", ByChange:="$S$4"
    SolverSolve
    End Sub

    I also tried this code:
    Sub SolverMacro()
    ' Example Solver VBA Macro
    SolverReset
    SolverOk SetCell:="$R$4", MaxMinVal:=3, ValueOf:="4275", ByChange:="$S$4"
    SolverSolve userFinish:=True
    End Sub
    Last edited by BHudPE; 02-25-2010 at 04:59 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: error while using solver in VBA

    Please reread the forum rules, and then edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

  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,758

    Re: error while using solver in VBA

    Did you set a reference to Solver?

    Visual basic Tools -> Reference -> Check the box marked Solver.xla

  4. #4
    Registered User
    Join Date
    01-13-2010
    Location
    Bakersfield, CA
    MS-Off Ver
    Excel 2003
    Posts
    37

    Re: error while using solver in VBA

    Alf, I looked and its not there. I run Vista64 SP2. Do you know where I can get the file?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: error while using solver in VBA

    In XP, in the VBE, Tools > References, browse to C:\Program Files\Microsoft Office\OFFICExx\Library\SOLVER, change the file type dropdown to *.xls, *.xla, and pick SOLVER.XLA

    I don't know if it's different in Vista.

    Solver comes with Excel, but installing it is a deliberate choice; you may need to reinstall to make sure you picked it up.
    Last edited by shg; 02-21-2010 at 12:27 PM.

  6. #6
    Registered User
    Join Date
    01-13-2010
    Location
    Bakersfield, CA
    MS-Off Ver
    Excel 2003
    Posts
    37

    Re: error while using solver in VBA

    I found it, and just added it. now to run.....
    thx

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: error while using solver in VBA

    BhudPE, please do not ignore shg's request to add code tags!

+ Reply to 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