Excel VBA:编译错误:子函数未定义 [英] Excel VBA: Compile Error: Sub of Function not Defined
问题描述
我正在尝试解决以下代码的问题,但我找不到方法。每当我尝试宏,我得到一个错误子或功能未定义。并且调试器以黄色Sub Solver_Overtime()和高亮蓝色SolverRest亮起亮点。
Sub Solver_OverTime()
pre>
激活
SolverReset
SolverOptions MaxTime:= 100,_
迭代:= 100,_
精度:= 0.000001,_
AssumeLinear:= True,_
StepThru:= False,_
估计:= 1,_
衍生:= 1,_
SearchOption:= 1,_
IntTolerance:= 5,_
缩放:= False,_
收敛:= 0.0001,_
AssumeNonNeg:= True
SolverAdd CellRef:= NET,关系:= 3,FormulaText:=NET_LIMIT
SolverAdd CellRef:=shftCount,关系:= 1,FormulaText:=shftCountLimit
SolverAdd CellRef:=schTemplate := 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
我不确定问题是什么,因为它在另一台电脑上运行正常。
谢谢提前。
解决方案我跟进了Tim William的说明,通过转到工具>参考>求解。它完成了这项工作,并按照预期工作。
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.
这篇关于Excel VBA:编译错误:子函数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!