Excel VBA: Compile Error: Sub of Function not Defi

2019-07-29 07:29发布

I'm trying to solve a problem with the following code but I just can't find a way around it. Whenever I try the Macro, I get an error "Sub or Function not defined". and the debugger highlights in yellow "Sub Solver_Overtime() and highlights in blue "SolverRest"

Sub Solver_OverTime()
Application.ScreenUpdating = False
Sheets("OverTime").Activate
SolverReset
SolverOptions MaxTime:=100, _
    Iterations:=100, _
    Precision:=0.000001, _
    AssumeLinear:=True, _
    StepThru:=False, _
    Estimates:=1, _
    Derivatives:=1, _
    SearchOption:=1, _
    IntTolerance:=5, _
    Scaling:=False, _
    Convergence:=0.0001, _
    AssumeNonNeg:=True
SolverAdd CellRef:="NET", Relation:=3, FormulaText:="NET_LIMIT"
SolverAdd CellRef:="shftCount", Relation:=1, FormulaText:="shftCountLimit"
SolverAdd CellRef:="schTemplate", Relation:=4, FormulaText:="integer"

SolverOk setcell:=Sheets("OverTime").Range("Intervals[[#Totals],[OT]]"), MaxMinVal:=2, ValueOf:="0", ByChange:=Sheets("OverTime").Range("Template_Schedule[COUNT]")
'SolverOk SetCell:="TargetCell", MaxMinVal:=2, ValueOf:="0", ByChange:="schTemplate"
SolverSolve True
End Sub

I'm not certain what the problem is because it runs just fine on another computer.

Thanks in advance.

1条回答
Rolldiameter
2楼-- · 2019-07-29 07:44

I followed up on Tim William's instructions to add a Reference to the Solver Library by going to Tools > References > Solver. It did the job and it works as intended.

查看更多
登录 后发表回答