|
楼主 |
发表于 2023-5-7 09:25
|
显示全部楼层
找到原因了,找到原因了,需要再rng的后面加上address就行了,昨天晚上搞的头蒙蒙的,没有想到这个错误。代码如下:
Sub TestSub2()
Dim i As Long, j As Long
Dim rng As Range, rng2 As Range, rng3 As Range, rng4 As Range
i = Range("G1").Value
j = Range("J1").Value
Set rng = Range("B4").Resize(i, j)
Set rng2 = Range("B24").Resize(1, j)
Set rng3 = Range("B25").Resize(1, j)
Set rng4 = Range("L4").Resize(i, 1)
SolverReset '重置求解器设置
SolverOk SetCell:=Range("L24"), MaxMinVal:=2, ValueOf:=0, ByChange:=rng.Address, _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=rng2.Address, Relation:=2, FormulaText:=rng3.Address
SolverAdd CellRef:=rng.Address, Relation:=4, FormulaText:="integer"
SolverAdd CellRef:=rng4.Address, Relation:=3, FormulaText:="0"
SolverOk SetCell:=Range("L24"), MaxMinVal:=2, ValueOf:=0, ByChange:=rng.Address, _
Engine:=2, EngineDesc:="Simplex LP"
SolverSolve UserFinish:=True '执行,但是不显示规划求解对话框
SolverFinish KeepFinal:=1 '结果返回单元格
End Sub |
评分
-
1
查看全部评分
-
|