以编程方式添加VBA解算器约束

以编程方式添加VBA解算器约束,vba,excel,Vba,Excel,我正在编写一个代码,它将循环遍历一列,并为单元格值为0的每一行的解算器模型添加约束 到目前为止,我已经尝试过这个,但它不起作用 For Each cell In Range("B11:B193").Cells If cell.Value = 0 Then SolverAdd CellRef:=(Cells.Address), Relation:=2, FormulaText:="0" End If Next 尝试更改此选项: SolverAdd CellRef:=(Cells.Addres

我正在编写一个代码,它将循环遍历一列,并为单元格值为0的每一行的解算器模型添加约束

到目前为止,我已经尝试过这个,但它不起作用

For Each cell In Range("B11:B193").Cells
If cell.Value = 0 Then
SolverAdd CellRef:=(Cells.Address), Relation:=2, FormulaText:="0" 
End If

Next
尝试更改此选项:

SolverAdd CellRef:=(Cells.Address), Relation:=2, FormulaText:="0"
为此:

SolverAdd CellRef:=(cell.Address), Relation:=2, FormulaText:="0"
更新:

由于您的
For
行,您可能会收到该错误

尝试更新到以下内容:

For Each Cell In Range("B11:B193")
    If Cell.Value = 0 Then
        SolverAdd CellRef:=(Cell.Address), Relation:=2, FormulaText:="0"
    End If
Next

对于范围(“B11:B193”,范围(“0”))中的每个单元格。Cells solverdd CellRef:=(cell.Address),Relation:=2,FormulaText:=“0”下一个单元格
我收到一个错误Run0time错误“1004”方法对象范围“\u Global”失败了几件事<代码>范围。单元格不起任何作用<代码>范围和
单元格
都是引用工作表中一个或多个单元格的方法,但它们不能一起工作<代码>范围(“0”)在VBA中没有任何意义。