+ Reply to Thread
Results 1 to 3 of 3

Solver: no solution

  1. #1
    Registered User
    Join Date
    04-30-2006
    Posts
    55

    Solver: no solution

    Hi,

    First of all, I'd like to say thanks to everyone here; I've picked up more on this forum than from any book...

    I have constructed a macro that calls solver, enters constraints and solves the optimization problem. However, for some constraints there will be no solutions. Unfortunately, solver will give me the nearest value instead of stating N/A (which I would prefer). Is there a code to resolve this? Thanks in advance! (Below is my code, which I know is inefficient, but don't mind that, I'll work on that later).

    Please Login or Register  to view this content.
    Thanks again, kind regards,

    Peter1999

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811
    Interesting problem.

    Without specifics of your spreadsheet model, I can only talk in generalities.

    The first step in the solution is how to identify when a solution exists and when it doesn't. If there is a readily identifiable condition that you could test for after Solver has finished, that might be the easiest.

    As an exercise, I made up my own spreadsheet that I could solve with Solver, then recorded a macro that setup the basic code.

    VBA help calls "solversolve" a function, so I expected that it should return a value, and hopefully that value would be related to whether or not Solver had converged to a solution. I changed that line of code to
    Please Login or Register  to view this content.
    Sure enough, when Solver found a solution, it returned 0, when it couldn't find a feasible solution, it returned 5.

    I don't know of anywhere where the return values for the solversolve function are documented, but I expect if you spent some time exploring your specific problem, you would be able to identify what return values represent "no solution" for you specific spreadsheet model. This assumes that Solver recognizes that it didn't come to a solution. I'm also assuming that the result from solversolve will be reasonably consistent from run to run.

    Using one of those two approaches, you can then identify the "no solution" condition. Then, simply put NA where you want it to be.
    Please Login or Register  to view this content.
    The only thing to note in this snippet is that if celltomodify contains a formula, you will lose the formula when you set it to NA. If this is what you want, make sure you leave yourself a way to recover the formula the next time you need it.

    Hope that helps.

  3. #3
    Registered User
    Join Date
    04-30-2006
    Posts
    55
    Thanks, I'll give that a try

    Peter1999

+ 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