+ Reply to Thread
Results 1 to 8 of 8

Excel VBA Solver Not Working

  1. #1
    Registered User
    Join Date
    03-16-2016
    Location
    indiana, US
    MS-Off Ver
    2016
    Posts
    33

    Excel VBA Solver Not Working

    Hello,
    I am having trouble getting my solver to work through VBA. If I use the Solver in the Data ribbon it works, but I cannot get the VBA code to work. I'm guessing there is an issue with my named ranges, but I can't figure it out.
    When running the code, the Solver Results box says "Error in model. Please verify that all cells and constraints are valid."


    Please Login or Register  to view this content.
    Last edited by alansidman; 10-08-2016 at 12:26 AM. Reason: added code tags. Please forum rules and abide by them in the future

  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: Excel VBA Solver Not Working

    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with CODE tags.

    Gracias.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: Excel VBA Solver Not Working

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    03-16-2016
    Location
    indiana, US
    MS-Off Ver
    2016
    Posts
    33

    Re: Excel VBA Solver Not Working

    My apologies. It won't happen again.

  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: Excel VBA Solver Not Working

    Try this:

    Please Login or Register  to view this content.
    Last edited by shg; 10-08-2016 at 02:49 AM.

  6. #6
    Registered User
    Join Date
    03-16-2016
    Location
    indiana, US
    MS-Off Ver
    2016
    Posts
    33

    Re: Excel VBA Solver Not Working

    shg,
    Thanks for the help. However, when I run that I get a Method 'Range' of object'_Worksheet' failed error on the SolverOk function. I am trying to run solver with a command button. I have made sure the solver is added in the vba reference list. Do I need to change things for it to work with the command button? Note: the command button is on the "Main" page and has code proceeding the solver code.

    Thanks in advance for any help.

  7. #7
    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: Excel VBA Solver Not Working

    Post a workbook.
    Last edited by shg; 10-09-2016 at 01:44 AM.

  8. #8
    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: Excel VBA Solver Not Working

    Ah, missed one:

    Please Login or Register  to view this content.
    That cell must be on the active sheet.
    Last edited by shg; 10-09-2016 at 06:17 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Solver function is not working
    By giscosta_br in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-16-2015, 12:16 PM
  2. Solver Not Working
    By stjohns88 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-01-2014, 09:19 AM
  3. Working with solver and constraints
    By Upnorthdyme in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-10-2013, 01:54 AM
  4. Solver Not Working?
    By Peter-27 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-20-2013, 07:04 PM
  5. Solver add in - Constraint not working
    By mkmed in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2013, 01:23 PM
  6. Excel Solver Not Working
    By TectonoGirl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-04-2013, 04:49 PM
  7. Solver has quit working
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-29-2009, 11:57 AM

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