找不到运行时错误424词典对象

时间:2019-06-10 16:50:38

标签: excel vba dictionary runtime-error runtime

我试图遍历数据集,将键添加到字典中以确定它们是否为重复条目。但是,当尝试测试关键字是否存在于字典中时,出现运行时错误424

我尝试将早期绑定更改为晚期绑定,并将'Triton'变量引入了当前模块。并且我确保所有变量都已声明。

Sub DupeCheckRec()

Dim TritonData As Variant
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim tempArr()
Dim i As Long
Dim KeyVal As String

    TritonData = Triton.Sheets(1).UsedRange

    For i = 2 To UBound(TritonData, 1)

        KeyVal = TritonData(i, 2) & TritonData(i, 3) & TritonData(i, 5) & TritonData(i, 6) & TritonData(i, 7) & TritonData(i, 10) & TritonData(i, 20)

        If dict(KeyVal).Exists = True Then

            tempArr(i, 1) = TritonData(i, 2)
            tempArr(i, 2) = TritonData(i, 3)
            tempArr(i, 3) = TritonData(i, 5)
            tempArr(i, 4) = TritonData(i, 7)
        Else
            dict.Add Key, i
        End If

    Next i

End Sub

预期的结果是将任何重复添加到tempArr

0 个答案:

没有答案