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!
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!