简体   繁体   中英

User-defined type not defined error

Hi I am very new to VBA Excel Programming. I keep getting a "User-defined type not defined" error. I searched everywhere and cannot find the answer to my specific problem. A lot of the solutions required adding references, which doesn't seem to apply to my situation. The calculation returns properly but the error message drives me crazy. Also the macro call at the end is not happening.

    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

I even tried to make a simpler version but I still get the same error.

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

Any feedback would be appreciated. Thanks.

    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 

I to ran your function with no errors, but...

A user defined function cannot modify other cells. In the call to AddRowDeleteConstants , whether or not it errors, the commands Copy , Insert and PasteSpecial do nothing because they are in effect called from the user defined function.

I'm not getting any errors with your code, but maybe you need to give your function a type?

Function MinutesOver(duration As Integer) as Integer

just a guess...

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