简体   繁体   English

Excel VBA:编译错误:未定义子功能

[英]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()”,以蓝色突出显示“ 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. 我按照Tim William的说明进行了操作,方法是转到“工具”>“引用”>“求解器”。 It did the job and it works as intended. 它完成了工作,并且按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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