遍历集合时对象需要错误“424”
Object required error '424' when iterating over Collection
当我 运行 我的函数时,我得到以下错误:
Run-Time error '424': Object Required
它突出显示了以下代码行:
For Each n In DataSet
这是我的完整代码:
'==============================|Find_Occurrences FUNCTION|=============================='
' Given a collection and a search value, return the number of occurrences of the search
' value in the collection, as an Integer. If it does not exist, return the integer 0
Function Find_Occurrences(DataSet As Collection, What As Variant) As Integer
Dim Count As Integer
Count = 0
Dim n As Variant
For Each n In DataSet ''''''''''''''''''Object required error'''''''''''''''''
'MsgBox (TypeName(What))
If (TypeName(n) = TypeName(What)) And (n = What) Then
Count = Count + 1
End If
Next n
Find_Occurrences = Count
End Function
有谁知道是什么原因导致的,无论是在我的代码中还是在我的代码之外?
调用函数时,错误实际上是在函数外部。它没有传入 DataSet 的集合,而是什么都不传入。
当我 运行 我的函数时,我得到以下错误:
Run-Time error '424': Object Required
它突出显示了以下代码行:
For Each n In DataSet
这是我的完整代码:
'==============================|Find_Occurrences FUNCTION|=============================='
' Given a collection and a search value, return the number of occurrences of the search
' value in the collection, as an Integer. If it does not exist, return the integer 0
Function Find_Occurrences(DataSet As Collection, What As Variant) As Integer
Dim Count As Integer
Count = 0
Dim n As Variant
For Each n In DataSet ''''''''''''''''''Object required error'''''''''''''''''
'MsgBox (TypeName(What))
If (TypeName(n) = TypeName(What)) And (n = What) Then
Count = Count + 1
End If
Next n
Find_Occurrences = Count
End Function
有谁知道是什么原因导致的,无论是在我的代码中还是在我的代码之外?
调用函数时,错误实际上是在函数外部。它没有传入 DataSet 的集合,而是什么都不传入。