我有一个问题,我希望有人可以提供帮助。我把一些vba代码放在一起,有excel循环求解器(设置为进化方法)。代码如下:
Sub Repeat_Solver()
Worksheets("DC Ranking by CM (All DC costs)").Activate
limit = 148
i = 147
Application.ScreenUpdating = True
Do Until i = limit
If Range("BV" & i).Value = "Y" Then
SolverReset
SolverOk SetCell:="$EQ$" & i, MaxMinVal:=1, ValueOf:=0, ByChange:="$CA$" & i, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$CG$" & i, Relation:=3, FormulaText:="45"
SolverAdd CellRef:="$CH$" & i, Relation:=1, FormulaText:="0.4"
SolverAdd CellRef:="$CA$" & i, Relation:=1, FormulaText:="$E$" & i
SolverAdd CellRef:="$CA$" & i, Relation:=4, FormulaText:="integer"
SolverOptions MaxTime:=60, Iterations:=200, Precision:=0.000001, _
AssumeLinear:=False, StepThru:=False, Estimates:=1, _
Derivatives:=1, SearchOption:=1, IntTolerance:=1, _
Scaling:=False, Convergence:=0.000001, AssumeNonNeg:=True, _
PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, _
Multistart:=False, RequireBounds:=False, MaxSubproblems:=3, _
MaxIntegerSols:=2, SolveWithout:=False, MaxTimeNoImp:=30
SolverOk SetCell:="$EQ$" & i, MaxMinVal:=1, ValueOf:=0, ByChange:="$CA$" & i, _
Engine:=3, EngineDesc:="Evolutionary"
SolverOk SetCell:="$EQ$" & i, MaxMinVal:=1, ValueOf:=0, ByChange:="$CA$" & i, _
Engine:=3, EngineDesc:="Evolutionary"
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
i = i + 1
Else
i = i + 1
End If
Loop
End Sub
当我设置limit=147
和i=146
(仅针对第146行运行它)时,它可以正常工作 - 但出于某些奇怪的原因,当我为limit=148
运行它时{{1} (如上面的代码所示),它停止在'设置问题... 33%'然后excel停止响应。
我甚至尝试在第147行手动运行求解器(没有vba代码),但仍然存在同样的问题 - excel崩溃。 (如果我将求解器设置为GRG非线性而不是进化的话,它似乎确实有效,奇怪的是。)
有谁知道我做错了什么?在此先感谢您的帮助!