跟踪更改时,使用VBA获取编译错误

时间:2017-11-30 03:00:02

标签: excel vba excel-vba compiler-errors

我收到编译错误" byRef参数类型不匹配。" ANy如何提醒我这是什么,或者我如何清除它?我检查了其他子功能,vOldArr是所有子功能的范围。错误来自Worksheet_Change子

    Dim vOldVal
    Dim vOldArr
Private Sub Worksheet_SelectionChange(ByVal target As Range)
    vOldVal = target.Value
    Set vOldArr = target
End Sub

Private Sub Worksheet_Change(ByVal target As Range)

     Call Get_Dirction(vOldVal, target, vOldArr)

End Sub

Sub Get_Dirction(vOldVal As Variant, target As Variant, vOldArr As Range)
    If target.Count = 1 Then
        Call Check_Change_Single(vOldVal, target)
        Exit Sub
    Else
        Call Check_Change_Mult(vOldArr, target)
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

传递的参数 docker run node npm -v 必须具有过程中预期的精确数据类型。

例如,如果您在预期ByRef时尝试传递Long变量,则会发生此错误。

示例

Integer

运行代码时,您将看到错误

enter image description here

在你的情况下,你有

Sub Sample()
    Dim SampleValue As Long

    SampleValue = 1

    SomeProcedure SampleValue
End Sub


Sub SomeProcedure(l As Integer)
    '
    '~~> Some Code
    '
End Sub

Sub Get_Dirction(vOldVal As Variant, target As Variant, vOldArr As Range) 期待 2个变种和1个范围

Get_Dirction预计为vOldArr,但会获得Range因此错误。

enter image description here

<强>解决方案

Variant

中声明vOldArrRange

OR

Private Sub Worksheet_Change(ByVal target As Range)

中声明vOldArrVariant