Excel 2016 VBA solver constraints

Excel 2016 VBA solver constraints



I am trying to run an automatic solver over a column of values. Target, reference and constraints cells are all in the same row, and they shift down with the target cell while running the solver throughout the column. The target cell has to be minimized, by changing the reference cell on the same row, under the constrain requiring to keep a third cell (that depends on the reference cell value) greater or equal than a fourth cell. None of the cells contain integers, all of them contain decimal values.



To resume:

Target cell (to be minimized) : P13

Reference cell (changing cell) : L13

Constrain (where M13 depends on L13) : M13 >= F13



all down to row 8795, shifting accordingly all the cells before mentioned.



The solver works fine running it manually row by row, but trying to automatize it in order to avoid 8762 iterations it doesn't respect the constrain. I have tried to remove " ", to add SolverReset and to put the constraint on top of the instructions, but nothing worked well. The code is:


Private Sub CommandButton1_Click()

Dim count As Integer
count = 13
Do While count <= 8795

SolverOk SetCell:=Cells(count, 16), MaxMinVal:=2, ByChange:=Cells(count, 12)
SolverAdd CellRef:=Cells(count, 13), Relation:=3, FormulaText:=Cells(count, 6)

SolverSolve userfinish:=True

count = count + 1
Loop
End Sub



I was trying to change constraint and I have noticed where probably the bug is: after running the code, if I open the solver I can see the last constraint used by the code. As you can see in the image below, I've tried to set a new constraint L13<=H13, where H13= 9,272 but the solver has 9272190.... maybe it is not "seeing" the decimal separator. Any idea? enter image description here



Thank you for your time.





Is it not SolverReset instead of SolverRestart?
– Pierre44
Aug 27 at 12:27


SolverReset


SolverRestart





Yes, you are right, typing error. However, the outcome is the same and it doesn't consider the constraint while iterating.
– Luca91
Aug 27 at 12:36









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)