I am using VBA to automatically enter maximum & minimum constraints for a cells value in Excel's solver. I have named ranges in the worksheet that I use to input a user defined maximum/minimum for the value.
It works for every value except when the user places "40" in the cell. When 40 is the value, the solver constraint is not added. There are no errors, the code runs fine, but the solver just decides not to add the 40 constraint. If I change 40 to any other number, it adds it just fine.
Here is an example of the code that adds the constraints to the solver. If the value of either xMAX or xMIN is 40, then it just decides not to add it to the solver. Any other value works fine which tells me it's not a code issue. HELP! 40 is a very common value.
It works for every value except when the user places "40" in the cell. When 40 is the value, the solver constraint is not added. There are no errors, the code runs fine, but the solver just decides not to add the 40 constraint. If I change 40 to any other number, it adds it just fine.
Here is an example of the code that adds the constraints to the solver. If the value of either xMAX or xMIN is 40, then it just decides not to add it to the solver. Any other value works fine which tells me it's not a code issue. HELP! 40 is a very common value.
Code:
'x must be between 0 & 40:
SolverAdd CellRef:=Range("x").Offset(-1), Relation:=1, FormulaText:=Range("xMAX")
SolverAdd CellRef:=Range("x").Offset(-1), Relation:=3, FormulaText:=Range("xMIN")