excel中的批量规划求解
1 Sub test() 2 3 Dim MaxRow As Integer, i As Integer 4 Dim iA As Integer, iB As Integer 5 Dim StrFormula1 As String, StrFormula2 As String 6 Worksheets("Sheet1").Activate 7 iRows = 57 '获取总的行数 8 For i = 2 To iRows 9 SolverReset '重置规划求解 10 SolverOk SetCell:=Replace("$J$2", "2", i), MaxMinVal:=3, ValueOf:="0", byChange:=Replace("$G$2:$H$2", "2", i) '规划求解中的目标单元和可变单元 11 SolverAdd CellRef:=Replace("$K$2", "2", i), Relation:=2, formulaText:=0 '规划求解中的约束 12 SolverAdd CellRef:=Replace("$H$2", "2", i), Relation:=3, formulaText:=1 '规划求解中的约束 13 SolverSolve UserFinish:=True '返回规划求解而不显示对话框 14 Next 15 16 17 End Sub