将列的值收集到数组中以加快处理速度。将频率作为每个键的项传输到字典的键。这张工作表很大,很容易找到第十大频率。去掉任何频率较低的东西。
Option Explicit
Sub gfdrew()
Dim i As Long, j As Long, arr As Variant, k As Variant, dict As Object
Set dict = CreateObject("scripting.dictionary")
With Worksheets("sheet6")
arr = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp)).Value2
End With
For i = LBound(arr, 1) To UBound(arr, 1)
dict.Item(arr(i, 1)) = dict.Item(arr(i, 1)) + 1
Next i
j = Application.Large(dict.items, Application.Min(10, dict.Count))
For Each k In dict.keys
If dict.Item(k) < j Then dict.Remove (k)
Next k
arr = dict.keys
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i)
Next i
End Sub