VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • excel vba教程之数组重复值的个数为最大

1.  数组重复值的个数为最大

 ‘Book1007.xls
‘http://excel.aa.topzj.com/thread-394037-1-1.html
Sub zuiduo1009()
'2007/10/9
Dim arr, arr2, i%, j%, x$, d As Object, t, n%, k, aa, r1
Sheets("Sheet2").Activate
arr = [a1:gh500]     '赋值给数组
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To 500
    For j = 1 To 190
        x = arr(i, j)
        If Not d.exists(x) Then
            d.Add x, 1
        Else
            d(x) = d(x) + 1
           
        End If
    Next j
Next i
n = d.Count           ‘不重复值的数量
t = d.items     ‘各个重复值的重复次数数组
k = d.keys     ‘不重复值的数组
For i = 0 To n - 1
    Cells(i + 1, "gj") = t(i)
    Cells(i + 1, "gk") = k(i)
Next i
    aa = Application.WorksheetFunction.Max(t)
    Set r1 = Range("gj1:gj" & n).Find(aa)
    If Not r1 Is Nothing Then
        [gl1] = Cells(r1.Row, "gk")
    End If
End Sub

相关教程