我有解决方案vba代码在Windows上工作正常(Excel 2013),但是在使用Excel 2011的macOS上存在一些问题。这是一个代码:
SolverReset
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:="$CA$3", Relation:=1, FormulaText:="100000"
SolverAdd CellRef:="$CA$10", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$CA$7", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$8", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$9", Relation:=2, FormulaText:="=1"
SolverOptions MaxTime:=100, Iterations:=100, precision:=0.000001, Convergence:= _
0.0001, StepThru:=False, Scaling:=False, AssumeNonNeg:=True, Derivatives:=1
SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
IntTolerance:=0, SolveWithout:=False, MaxTimeNoImp:=30
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
问题是在应用上述代码后解算器中缺少以下条件:
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
一个有趣的事情是,只有SetCell和ByChange不是从第二个条件设置的,而是引擎类型" Simplex LP"很好。 我通过录制我手动设置的宏来获取代码,所以不应该有任何问题。
答案 0 :(得分:1)
经过大量的浪费时间后,我设法解决了这个问题。似乎" _"存在问题。被追捕:
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow, _
Engine:=2, EngineDesc:="Simplex LP"
我按照以下方式解决了这个问题:
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow, _
Engine:=2, EngineDesc:="Simplex LP"