开发者

User-defined type not defined error

开发者 https://www.devze.com 2023-03-12 14:47 出处:网络
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 requi

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开发者_JAVA百科") * 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号