我希望将单元格插入求解器宏的“bychange”部分,但我不知道如何添加所有单元格。我通过定义一个范围然后使用 range.address 来尝试它,但是当我尝试扩展它并在 by change 部分中使用更多单元格(通过定义范围)时它不起作用。
Sub Solver_button()
' Nominates ranges that will be used in the solver
Dim C_col As Range
Dim D_col As Range
Dim E_col As Range
Dim F_col As Range
Dim G_col As Range
Dim H_col as Range
On Error Resume Next
If range("$c$4").Value = "yes" Then C_col = range("$C$7")
If range("$d$4").Value = "yes" Then D_col = range("$D$7")
If range("$e$4").Value = "yes" Then E_col = range("$e$7")
If range("$f$4").Value = "yes" Then F_col = range("$f$7")
If range("$g$4").Value = "yes" Then G_col = range("$g$7")
If range("$h$4").Value = "yes" Then H_col = range("$h$7")
SolverOk SetCell:="$O$9", MaxMinVal:=2, ValueOf:=0, ByChange:=[c_col.address,d_col.address,e_col.address,f_col.address,g_col.address,h_col.address],
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve