SolverAdd not adding a criterion.

GuyPrall5963

New Member
Joined
Sep 2, 2009
Messages
1
The code below is part of a macro that programmatically sets criteria in Solver and runs Solver. The process has appeared to have worked perfectly for multiple machines and versions of Excel for about a year. I am using Excel 2003. However, I have come across an error that I cannot fathom. When the value in the cell that is referenced by "Sheet5.Cells(9, 2)" is either the number 8 or the number 9, this criterion is not added! I can plug in, say "6" or "10" or indeed any other number, and the criterion is added - but not with 8 or 9.

Code:
Application.Run "Solver.xla!SolverAdd", _
                    Sheet1.Cells(1, 3), _
                    Sheet1.Cells(2, 3), _
                    Sheet5.Cells(9, 2)

Even if I use the more normal code of

Code:
SolverAdd CellRef:=Sheet1.Cells(1, 3), _
        Relation:=Sheet1.Cells(2, 3), _
       FormulaText:=Sheet5.Cells(9, 2)

... it still fails to add the criterion if the cell value is 8 or 9.

If I manually set criteria using the Solver toolbar, there is no problem with it accepting the values of 8 or 9 as a constraint, naturally. Since this particular constraint is "price not greater than" it is causing me significant issues since, if this constraint is not included, Solver assumes that price is not an issue so gives me very expensive solutions! Interestingly this issue has arisen as a result of the recession - we have never had to set the maximum price level as low as 8 or 9!

Does anyone have any insights into what might be going on?
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,215,526
Messages
6,125,328
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top