Fork me on GitHub

(VBA)返回数组中相同值的索引

View Code
Sub GetSameValue()
Dim arr(0)
Dim i As Integer, cellval As Integer, tempval As Integer
Dim varstr As String
arr(0) = Array(9, 1, 4, 6, 1, 1, 1, 1)
For i = 0 To UBound(arr(0))
cellval = arr(0)(i)
If i = 0 Then
tempval = cellval
Else
If cellval < tempval Then
tempval = cellval
varstr = i
ElseIf cellval = tempval Then
varstr = varstr & "," & i
End If
End If
Next i
Debug.Print varstr
End Sub
posted @ 2011-11-29 20:12  逍遥メ风  阅读(680)  评论(0编辑  收藏  举报