我一直在努力想出一个能够提取出现在列中的 10 个最常见名称并将它们存储到数组中以供进一步使用的程序。
最佳答案
将列的值收集到一个数组中以加快处理速度。以频率作为每个键的项目转移到字典的键。工作表的大可以轻松找到第 10 大频率。删除任何频率较低的东西。
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
关于excel - 获取列中最常用的 10 个名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52214927/