VBA Select案例类型不兼容

时间:2018-03-21 21:08:28

标签: vba types runtime incompatibility

我有这个sub和你在下面看到的这个功能。它给了我一个运行时错误13:在下一行输入不兼容性,我不知道什么是错的

Select Case ((Cell.Offset(0, -2).Value - Cell.Offset(0, -1).Value) - (CellX.Offset(0, -2).Value - CellX.Offset(0, -1).Value))

我正在处理这段代码几个小时,所以你是我最后的选择。

您可能还需要知道,在Range rngX的单元格中,存在具有浮点数的单元格和没有内容的单元格,Cell.Offset(0,-2)Cell.Offset(0,-1)中存在整数或没有内容的细胞

Sub X()

    Dim boolFunction as Boolean

    With ThisWorkbook.Sheets("IntTab")
        boolFunction = Function1(.Range("O2:O19"))
        boolFunction = Function1(.Range("AA2:AA19"))
    End With

End Sub


Function Function1(ByVal rngX As Range) As Boolean

    Dim intTab As Integer

    For Each Cell In rngX
        intTab = 1
        For Each CellX In rngX
            Select Case Cell.Value - CellX.Value
                Case Is > 0
                    'Do nothing
                Case Is = 0
                    Select Case ((Cell.Offset(0, -2).Value - Cell.Offset(0, -1).Value) - (CellX.Offset(0, -2).Value - CellX.Offset(0, -1).Value))
                        Case Is > 0
                            'Do nothing
                        Case Is = 0
                            'Do nothing
                        Case Is < 0
                            intTab = intTab + 1
                    End Select
                Case Is < 0
                    intTab = intTab + 1
            End Select
        Next CellX
        Cell.Offset(0, (-9)).Value = intTab
    Next Cell

    Function1 = True

End Function

1 个答案:

答案 0 :(得分:0)

我怀疑那些“没有内容的单元格”可能会有一些空格内容

所以只需通过from __builtins__ import hash as builtin_hash hash = builtin_hash(foo) 函数

将它们转换为零
Val()