功能:要解决工作表第一部分(在A1:N280内)的求解器问题,然后继续解决相同的求解器问题(参数值略有不同)右边十五列(即O1:AB280) ,直到总共60个段。这些段都具有类似的格式。
Sub SolverAutomator()
Dim i, k As Integer
Dim var1, var1a As Range
Dim from1, from1a As Range
Dim to1, to1a As Range
Dim sum1, sum1a As Range
For i = 0 To 60
k = i * 15
Set var1 = Range("$M$151")
Set var1a = var1.Offset(0, k)
Set from1 = Range("$M$140")
Set from1a = from1.Offset(0, k)
Set to1 = Range("$M$149")
Set to1a = to1.Offset(0, k)
Set sum1 = Range("$N$149")
Set sum1a = sum1.Offset(0, k)
SolverReset
SolverOK setCell:="var1a", maxMinVal:=2, ValueOf:=0, byChange:="from1a: to1a" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd cellRef:=sum1a, relation:=2, formulaText:="1"
SolverSolve
SolverSolve userFinish:=True
SolverFinish KeepFinal:=1
Next i
End Sub
我为可怕的编码道歉。
答案 0 :(得分:0)
未经测试,但我会做这样的事情:
For i = 0 To 60
k = i * 15
SolverReset
SolverOK setCell:=Range("M151").Offset(0, k), _
maxMinVal:=2, ValueOf:=0, _
byChange:=Range("M140:M149").Offset(0, k), _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd cellRef:=Range("N149").Offset(0, k), _
relation:=2, formulaText:="1"
SolverSolve
SolverSolve userFinish:=True
SolverFinish KeepFinal:=1
Next i