运行时错误';1004';:方法';范围';对象的'_全球';失败-解算器vba
我已经编写了这段代码,但它在第一行“SolverOk”开始出现错误。不知道如何解决,如有任何建议,将不胜感激运行时错误';1004';:方法';范围';对象的'_全球';失败-解算器vba,vba,Vba,我已经编写了这段代码,但它在第一行“SolverOk”开始出现错误。不知道如何解决,如有任何建议,将不胜感激 Worksheets("Reconciliation").Activate Range("AM3").Select Do Until IsEmpty(ActiveCell) ActiveCell.Offset(0, 1).Range("A1:G1").Select Selection.ClearContents SolverReset SolverOk S
Worksheets("Reconciliation").Activate
Range("AM3").Select
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(0, 1).Range("A1:G1").Select
Selection.ClearContents
SolverReset
SolverOk SetCell:=ActiveCell.Select, MaxMinVal:=3, ValueOf:=0, ByChange:=Range(ActiveCell.Offset(0, 1).Range("A1:G1").Select), _
Engine:=2, EngineDesc:="Simplex LP"
SolverAdd CellRef:=Range("AN" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AO" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AP" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AQ" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AR" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AS" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AT" & (ActiveCell.Row)).Select, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:=Range("AQ" & (ActiveCell.Row)).Select, Relation:=1, FormulaText:=Range("AN" & (ActiveCell.Row)).Select
SolverOk SetCell:=ActiveCell.Select, MaxMinVal:=3, ValueOf:=0, ByChange:=Range(ActiveCell.Offset(0, 1).Range("A1:G1").Select), _
Engine:=2, EngineDesc:="Simplex LP"
SolverOk SetCell:=ActiveCell.Select, MaxMinVal:=3, ValueOf:=0, ByChange:=Range(ActiveCell.Offset(0, 1).Range("A1:G1").Select), _
Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
ActiveCell.Offset(1, 0).Activate
Loop
删除所有
。选择要传递给任何对象的参数中出现的任何调用:
SolverOk SetCell:=ActiveCell.Select
应该是
SolverOk SetCell:=ActiveCell
SolverAdd CellRef:=Range("AN" & (ActiveCell.Row))
及
应该是
SolverOk SetCell:=ActiveCell
SolverAdd CellRef:=Range("AN" & (ActiveCell.Row))
您想要传递一个范围
对象引用.Select
不会返回任何内容,它会选择范围,该范围将成为当前的选择
,并会影响ActiveCell
,这几乎不可能精确跟踪传递给过程的内容
而不使用对象引用:
Dim target As Range
Set target = ActiveCell 'best set it to an actual specific Range on a specific Worksheet.
'now work with it:
SolverOk SetCell:=target, ...
我非常怀疑SetCell:=ActiveCell.Select
是一个有效的参数,因为.Select
是一个过程,而不是一个函数-它不返回任何内容,只选择一个单元格。SolverReset
是否激活或选择任何内容?每个范围
调用都隐式地使用活动表
,这使您的代码非常脆弱。你需要阅读和重写一切。