Thank you for explanation.
it helps me to understand how this works
What seems to be important is that the range X4:X? should be equal to or less than the T4:T? range if it's greater you do get some funny results in the AD column. Could be fixed in the macro by adding this line.
Yes, whole range from column T:Z have same number of rows. allways
Dim i As Integer
Dim j As Integer
Cells(Application.Evaluate("MAX(IF(T4:T45<>"""",ROW(T4:T45)),0,1)"), "T").Select
i = ActiveCell.Row
Cells(Application.Evaluate("MAX(IF(AB4:AB45<>"""",ROW(AB4:AB45)),0,1)"), "AB").Select
j = ActiveCell.Row
SolverReset
SolverOk SetCell:="$AB$3", MaxMinVal:=1, ValueOf:=0, ByChange:="$X$4:$X$" & i, Engine:=1
SolverAdd CellRef:="$AD$4:$AD$10", Relation:=1, FormulaText:="20"
SolverAdd CellRef:="$W$45", Relation:=2, FormulaText:="$C$5"
SolverAdd CellRef:="$X$4:$X$" & i, Relation:=1, FormulaText:="20"
SolverAdd CellRef:="$X$4:$X$" & i, Relation:=3, FormulaText:="5"
SolverSolve
i = ActiveCell.Row
Range("X" & i + 1 & ":X44").ClearContents
End Sub
This is what i have right now, but still doesent work quite i imagined. Sometimes it leave last few rows blank ? But it works when I manually adjust in solver menu.
I think the main problem is with AD4:AD ? If macro could adjust last row in the solver constraint, then it would work perfectly. Same thing as in X column
Bookmarks