Excel - řešitel skrze VBA
Ahojte,
spouštím řešitele za pomocí makra. Řešitel bohužel umí nastavit na hodnotu pouze zadanou ručně, já však nechci pokaždé upravovat makro, když se změní vstup. Zkoušel jsem v makru: SolverOk SetCell:="$R$31", MaxMinVal:=3, ValueOf:="$M$16", ByChange:= _"$N$2:$N$14", tedy nastavit ValueOf namísto hodnoty odkazem na buňku,což však bohužel nefunguje. Nešlo by např. makrem dosadit do makra hodnotu do ValueOf podle hodnoty v buňce M16?
Pokud jste mě pochopili a umíte pomoci, budu velice šťastný
Děkuji
Zapsal jsem to takto, ale hlásí mi "Chyba modelu...".
Sub resitel()
'
' resitel Makro
'
'
SolverReset
SolverOk SetCell:="$R$31", MaxMinVal:=3, ValueOf:=Range("M16"), ByChange:= _
"$N$2:$N$14"
SolverAdd CellRef:="$V$3", Relation:=1, FormulaText:="$W$2"
SolverAdd CellRef:="$V$4", Relation:=1, FormulaText:="$W$3"
SolverAdd CellRef:="$V$5", Relation:=1, FormulaText:="$W$4"
SolverAdd CellRef:="$V$6", Relation:=1, FormulaText:="$W$5"
SolverAdd CellRef:="$V$7", Relation:=1, FormulaText:="$W$6"
SolverAdd CellRef:="$V$8", Relation:=1, FormulaText:="$W$7"
SolverAdd CellRef:="$V$9", Relation:=1, FormulaText:="$W$8"
SolverAdd CellRef:="$V$10", Relation:=1, FormulaText:="$W$9"
SolverAdd CellRef:="$V$11", Relation:=1, FormulaText:="$W$10"
SolverAdd CellRef:="$V$12", Relation:=1, FormulaText:="$W$11"
SolverAdd CellRef:="$V$13", Relation:=1, FormulaText:="$W$12"
SolverAdd CellRef:="$V$14", Relation:=1, FormulaText:="$W$13"
SolverAdd CellRef:="$R$18", Relation:=1, FormulaText:="$AB$2*$AC$2"
SolverAdd CellRef:="$R$19", Relation:=1, FormulaText:="$AB$3*$AC$2"
SolverAdd CellRef:="$R$20", Relation:=1, FormulaText:="$AB$4*$AC$2"
SolverAdd CellRef:="$R$21", Relation:=1, FormulaText:="$AB$5*$AC$2"
SolverAdd CellRef:="$R$22", Relation:=1, FormulaText:="$AB$6*$AC$2"
SolverAdd CellRef:="$R$23", Relation:=1, FormulaText:="$AB$7*$AC$2"
SolverAdd CellRef:="$R$24", Relation:=1, FormulaText:="$AB$8*$AC$2"
SolverAdd CellRef:="$R$25", Relation:=1, FormulaText:="$AB$9*$AC$2"
SolverAdd CellRef:="$R$26", Relation:=1, FormulaText:="$AB$10*$AC$2"
SolverAdd CellRef:="$R$27", Relation:=1, FormulaText:="$AB$11*$AC$2"
SolverAdd CellRef:="$R$28", Relation:=1, FormulaText:="$AB$12*$AC$2"
SolverAdd CellRef:="$R$29", Relation:=1, FormulaText:="$AB$13*$AC$2"
SolverAdd CellRef:="$R$30", Relation:=1, FormulaText:="$AB$14*$AC$2"
SolverOk SetCell:="$R$31", MaxMinVal:=3, ValueOf:=Range("M16"), ByChange:= _
"$N$2:$N$14"
SolverSolve
End Sub
Posílám řešení
Napřed vložím hodnotu která má vyjít do proměnné v a pak ji použiju jako parametr ValueOf. Spíš se trápím, aby mi to nezobrazovalo otravné modální okno, jestli chci uchovat výsledky řešení, doufám, že na to brzy přijdu.
Sub Resitel()
v=Range("M16")
'nebo také v=CStr(Range("M16"))
SolverOk SetCell:="$R$31", MaxMinVal:=3, ValueOf:=v, ByChange:=""$N$2:$N$14"
SolverSolve
End Sub
Zdravím J.Kratochvíl
další zajímavosti na mých stránkách makra.web.cz
Odkaz není funkční (respektive "nikam" nevede).
Díky za návrh