Solver constraint not working - know its a simple fix

cali_text

New Member
Joined
Dec 8, 2009
Messages
1
Hello,

I am using the solver function in VBA to simply maximize one variable subject to two constraints. I have coded them into VBA - one works, but the other one does not. The constraint that does not work refers to a summation of the cells equaling 1. Here is the code:

Sub Solver()

Application.Run "Solver.xla!SolverReset"
Application.Run "Solver.xla!SolverOk", "$C$9", 1, "0", "$I$6:$I$18"

''''''''''THE LINE BELOW IS THE PROBLEM CONSTRAINT, all of the other constraints work - the cell $I$21 is a summation formula, =Sum($I$6:$I$18), and the constraint is that this sum must be equal to 1.''''''''''''

Application.Run "Solver.xla!SolverAdd", "$I$21", 2, "1"
Application.Run "Solver.xla!SolverAdd", "$I$6:$I$18", 3, 0
Application.Run "Solver.xla!SolverAdd", "$I$6", 2, 0.05


Result = Application.Run("Solver.xla!SolverSolve", True)

End Sub

If anyone can help, I would be much obliged!
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Watch MrExcel Video

Forum statistics

Threads
1,122,539
Messages
5,596,754
Members
414,097
Latest member
FaeFen

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
Top