Dec 21 2021 07:32 AM
Hi Folks,
I am trying to give cell reference to solver add-in in excel VBA window, but i am unable to do so.
Can anyone please help me for the same?
Open for different approaches if this is not possible
Thanks
Dec 21 2021 08:33 AM
You have to specify ranges:
Sub Macro3()
SolverReset
SolverOk SetCell:=Range("I11"), MaxMinVal:=3, ValueOf:=Range("C3").Value, ByChange:=Range("G9"), _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=Range("G9"), Relation:=3, FormulaText:=0
SolverSolve UserFinish:=True
End Sub
Dec 21 2021 09:44 AM
Dec 21 2021 09:54 AM
@Hans Vogelaar
Sorry for the multiple post
PFA
Dec 21 2021 12:14 PM
That is because the total for A and B, without C is 182195, well over the target of 153500. So there is no solution.
If you either increase the target to above 182195, or decrease the percentage for A and/or C so that the total is less than 153500, the code will find a solution.
Dec 21 2021 09:25 PM
Dec 22 2021 04:03 AM
There would be a solution if you allowed the price to be negative. But I assume that that is not realistic.
Dec 22 2021 06:44 AM
In most real-world situations, prices cannot be less than zero.
But you can try it for yourself: if you allow the price to be negative, then Solver will find a solution.
See the attached version.