带循环的VBA解算器

时间:2017-05-09 08:37:29

标签: excel vba excel-vba solver

我正在尝试使用Solver创建一个循环,它继续向下行直到ActiveCell为空。我对VBA很新,并认为我在正确的轨道,但现在我的宏甚至没有超过第一部分。

任何建议都会非常感激 - 我很困惑!

Sub ReconciliationMacro()

    Workbooks("Solver Test File.xlsm").Activate
    Workbooks("Solver Test File.xlsm").Sheets("Reconciliation").Activate
    Cells(3, 39) = ActiveCell.Select
    Do While ActiveCell.Value <> Empty
    SolverReset
    SolverOk SetCell:=Cells(ActiveCell.Row, 39), MaxMinVal:=3, ValueOf:=0, ByChange:=Range(Cells(3, 40), Cells(3, 46)).Value, _
        Engine:=2, EngineDesc:="Simplex LP"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 40), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 41), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 42), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 43), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 44), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 45), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 46), Relation:=5, FormulaText:="binary"
    SolverAdd CellRef:=Cells(ActiveCell.Row, 43), Relation:=1, FormulaText:=Cells(ActiveCell.Row, 40)
    SolverOk SetCell:=Cells(ActiveCell.Row, 39), MaxMinVal:=3, ValueOf:=0, ByChange:=Range(Cells(3, 40), Cells(3, 46)).Value, _
        Engine:=2, EngineDesc:="Simplex LP"
    SolverOk SetCell:=Cells(ActiveCell.Row, 39), MaxMinVal:=3, ValueOf:=0, ByChange:=Range(Cells(3, 40), Cells(3, 46)).Value, _
        Engine:=2, EngineDesc:="Simplex LP"
    SolverSolve
    ActiveCell.Offset(1, 0).Select
    Loop
End Sub

0 个答案:

没有答案
相关问题