【发布时间】:2017-11-20 16:48:37
【问题描述】:
抱歉,这是另一个 VBA Solver 循环问题。我已经阅读了这里和其他地方发布的许多其他问题/答案,但是对于 VBA 新手(这是我尝试的第一件事),我无法确定我的错误。
我希望将单元格 Ii 设置为 0,同时更改单元格 Ji 和 Ki(保留结果),其中 i 是第 3 到 21 行。
我当前的代码没有出现任何错误,但结果只保留在循环的最后一行 - 请告知!我尝试过使用 range() 和 range.offset(来自其他示例)而不是 cells(),并且将活动工作表设置为无济于事。
我正在使用 Excel 2011 for Mac。
Sub SolveTwo()
'Not sure if this is necessary
Dim row As Integer
'Begin loop
For row = 3 To 21
'Test code shows it is stepping through loop
Cells(row, "U").Value = row
'Grab starting values from other columns
Cells(row, "J").Value = Cells(row, "S").Value
Cells(row, "K").Value = Cells(row, "T").Value
'Solver Code
SolverReset
SolverOptions Precision:=1e-05
SolverOk SetCell:=Cells(row, "I").Address, _
MaxMinVal:=3, ValueOf:=0, _
ByChange:=Cells(row, "J").Address & "," & Cells(row, "K").Address, _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
'Not sure if below is necessary
'SolverSave SaveArea:=Cells(row, "J").Address & "," & Cells(row,"K").Address
Next row
End Sub
【问题讨论】: