简体   繁体   中英

Excel VBA: Compile Error: Sub of Function not Defined

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM