Arrays Visual Basic-查找数组中某个值的匹配项
正如标题所说,我需要找出我的值在数组中出现的次数。在本例中,我要查找整数0出现的次数,以及它返回0的总数。有人知道它的语法吗?只需将Arrays Visual Basic-查找数组中某个值的匹配项,arrays,vba,Arrays,Vba,正如标题所说,我需要找出我的值在数组中出现的次数。在本例中,我要查找整数0出现的次数,以及它返回0的总数。有人知道它的语法吗?只需将SomeArray替换为分配给其他代码的Array Sub CountIntInArray() Dim SomeArray As Variant Dim ArrayPos As Long Dim Num0s As Long Num0s = 0 'Assuming you only have one level in th
SomeArray
替换为分配给其他代码的Array
Sub CountIntInArray()
Dim SomeArray As Variant
Dim ArrayPos As Long
Dim Num0s As Long
Num0s = 0
'Assuming you only have one level in the array
'otherwsie you will need to check each level as well
'See the help file on Ubound for more info
For ArrayPos = 0 To UBound(SomeArray)
If SomeArray(ArrayPos) = 0 Then
Num0s t = Num0s + 1
End If
'If you want to ignore the decimals then you can use
If Int(SomeArray(ArrayPos)) = 0 Then
Num0s t = Num0s + 1
End If
Next ArrayPos
End Sub
欢迎来到stackoverflow。请注意,这是一项代码编写或家庭作业完成服务。而是为了帮助代码中有错误的人,或者为代码的某一部分找到解决方案。但是,如果您知道如何使用数组,那么您将被问到的问题相当简单。请参见下面我的答案。享受StackOverflow谢谢你的帮助,我四处寻找它,但是我发现的大部分内容都是在数组中找到所有相同值的数量。