我的工作簿有三张纸,其中一张的名字是“数据”。
为什么 .select 方法不起作用?代码运行良好,没有给出错误,但从不选择/转到“数据”表......
Private Sub CommandButton1_Click()
Dim solverAvailable As Boolean
solverAvailable = CheckSolver()
Sheets("Data").Select
If solverAvailable = True Then
SolverReset
SolverOk SetCell:="$D$56", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$12:$C$13", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$H$56", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$12:$D$13", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$M$56", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$12:$E$13", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$F$77", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$14:$C$15", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$L$77", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$14:$D$15", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$S$77", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$14:$E$15", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$D$133", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$83:$C$84", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$H$133", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$83:$D$84", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$M$133", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$83:$E$84", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$F$157", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$85:$C$86", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$L$157", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$85:$D$86", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$S$157", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$85:$E$86", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$D$209", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$163:$C$164" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$H$209", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$163:$D$164" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$M$209", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$163:$E$164" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$F$231", MaxMinVal:=2, ValueOf:=0, ByChange:="$C$165:$C$166" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$L$231", MaxMinVal:=2, ValueOf:=0, ByChange:="$D$165:$D$166" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
SolverReset
SolverOk SetCell:="$S$231", MaxMinVal:=2, ValueOf:=0, ByChange:="$E$165:$E$166" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve True
End If
Beep
End Sub
我实际上希望工作表选择在 if 内,但如果它在那里,它会给出“9”错误:subscript out of range
!
理想情况下,我什至不想选择工作表 - 我想引用 Sheets("Data").Range(whatever),但这也会产生subscript out of range
错误。