用户定义类型未定义错误

问题描述:

嗨,我很新的VBA Excel编程。我不断收到“用户定义的类型未定义”错误。我到处搜索,找不到我的具体问题的答案。很多解决方案都需要添加引用,这似乎不适用于我的情况。计算正确返回,但错误消息让我疯狂!最后的宏调用也没有发生。用户定义类型未定义错误

Function MinutesOver(duration, start_time, end_time) 

     If Not (duration = "") Then 
     If ((duration * 60) > 600) Or (((duration * 60) + (start_time * 24 * 60)) > (TimeValue("17:00:00") * 24 * 60)) Then 
      MinutesOver = (duration * 60) - ((end_time - start_time) * 24 * 60) 
     Else 
      MinutesOver = "" 
     End If 
     Else 
     MinutesOver = "" 
     End If 

     Call AddRowDeleteConstants 

    End Function 

我甚至试图做出更简单的版本,但我仍然得到相同的错误。

Function MinutesOver(duration As Integer) 
     MinutesOver = duration 
    'Call AddRowDeleteConstants 
    End Function 

任何反馈,将不胜感激。谢谢。

Sub AddRowDeleteConstants() 
     'On Error GoTo NoConstants 
     With ActiveCell.EntireRow 
     .Copy 
     .Insert Shift:=xlDown 
     .SpecialCells(xlCellTypeConstants).ClearContents 
     End With 
    Exit Sub 

    'NoConstants: 
    'MsgBox "There were no constants to delete" 
    End Sub 
+0

什么是AddRowDeleteConstants?什么是错误? (如果你不能告诉,按功能MinutesOver(..线上的f9设置一个断点,运行呼叫,当打破以运行下一行时按F8) – 2011-06-10 16:42:55

+0

我用F8一路走过它,错误doesn直到完成后才会发生(在它到达End Function行后)AddRowDeleteConstants看起来像这样: – 2011-06-10 16:57:32

我来跑,没有错误的功能,但是......

用户自定义函数不能修改其他细胞。在致AddRowDeleteConstants的调用中,无论它是否错误,命令Copy,InsertPasteSpecial都不做任何事情,因为它们实际上是从用户定义的函数中调用的。

+0

谢谢,对于这些信息我可以住在这个错误中,但是由于从用户定义函数修改其他单元是不可能的,所以我将不得不提出一个不同的计划。 – 2011-06-11 17:29:40

我没有得到任何错误与您的代码,但也许你需要给你的函数的类型?

Function MinutesOver(duration As Integer) as Integer 

只是一个猜测...

+0

这似乎也不起作用,仍然得到相同的错误::( – 2011-06-10 17:54:21

+0

这个“猜测”是完全不相关的,没有用处...... -1 – 2011-06-11 13:43:16