我已经构建了以下函数,将轴承的格式从DD.MMSS更改为DD°MM'SS”,但是当函数到达我测试的自定义函数中嵌入的MRound命令时,出现了上述错误。

我已经阅读了许多与堆栈溢出时此类编译错误相关的问题,并怀疑该错误与VBA没有正确引用MRound函数有关,但是我不知道如何解决(如果是这种情况)。

非常感谢您的帮助!

函数测试(Bearing_DMS作为单个)作为字符串

Dim degrees As String
Dim minutes_working As Single
Dim minutes As String
Dim seconds_working As Single
Dim seconds As String

    'Determine degrees value
    If Int(Bearing_DMS) < 10 Then
        degrees = "    " & Int(Bearing_DMS)
        ElseIf Int(Bearing_DMS) >= 10 And Int(Bearing_DMS) < 100 Then
        degrees = "  " & Int(Bearing_DMS)
        Else
        degrees = Int(Bearing_DMS)
    End If

    'Determine minutes_working value
    minutes_working = (Bearing_DMS - degrees) * 100

    'Determine minutes value
    If minutes_working < 1 Then
        minutes = "00"
        ElseIf minutes_working >= 1 And minutes_working < 10 Then
        minutes = "0" & Int(minutes_working)
        Else
        minutes = Int(minutes_working)
    End If

    'Determine seconds_working value
    seconds_working = (minutes_working - minutes) * 100

    'Determine seconds value
    If seconds_working < 1 Then
        seconds = "00"
        ElseIf seconds_working >= 1 And seconds_working < 10 Then
        seconds = "0" & MRound(seconds_working, 1)
        Else
        seconds = MRound(seconds_working, 1)
    End If

    'Determine final value to display

    Test = degrees & "° " & minutes & "' " & seconds + Chr(34)

结束功能

最佳答案

MRound不是VBA函数。将MRound(seconds_working, 1)更改为WorksheetFunction.MRound(seconds_working, 1)

关于excel - 编译错误: Sub or function not defined (MRound),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54235420/

10-12 17:55