Results 1 to 2 of 2
2008-04-04, 21:41 #1
- Join Date
- Feb 2004
- Thanked 0 Times in 0 Posts
SolverAdd function problem (solution) (2003)
Yesterday, I found myself faced with the next problem. I wrote a code which had Solver functions to optimize a problem (it was an easy one).
The code was:
SolverAdd CellRef:="$I$22", Relation:=2, FormulaText:="0"
SolverOk SetCell:="$F$29", MaxMinVal:=2, ValueOf:="0", ByChange:="$F$22:$H$22"
Surprisingly, when the code was ran, Solver found a bad solution. However, when I ran Solver from the menu, it found the correct one.
So, I tried many different solutions but I couldn't come to a successful one. The problem was that the restriction wasn't added. I searched in Google and found that "Solver sometimes does not add restrictions with SolverAdd when the field FormulaText is written in a specified way". In my case, this way was -> FormulaText:="0". It sometimes doesn't work with 0 nor 1. To solve this problem you have to write:
SolverAdd CellRef:="$I$22", Relation:=2, FormulaText:="=0" (an equal sign was added next to the zero)
It is recommended to write this whenever you have a number as the restriction. If you weren't to, the restriction could not be added.
Hope this helps!
All the best,
2008-04-04, 21:44 #2
- Join Date
- Mar 2002
- Thanked 28 Times in 28 Posts
Re: SolverAdd function problem (solution) (2003)
Thanks for posting, that should be useful to others!