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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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