Sub CountRepeatNum()
Dim dict As Object
Dim lastRow As Long, i As Long
'创建字典统计每个值出现次数
Set dict = CreateObject("Scripting.Dictionary")
dict.CompareMode = vbTextCompare
'关闭屏幕闪烁,提速
Application.ScreenUpdating = False
'获取A列最后一行数据
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
'第一轮:遍历A列统计所有值的总次数
For i = 2 To lastRow
If Not IsEmpty(Cells(i, 1)) Then
dict(Cells(i, 1).Value) = dict(Cells(i, 1).Value) + 1
End If
Next i
'第二轮:把统计次数填入B列
For i = 2 To lastRow
If Not IsEmpty(Cells(i, 1)) Then
Cells(i, 2).Value = dict(Cells(i, 1).Value)
End If
Next i
Application.ScreenUpdating = True
MsgBox "执行完成,B列已填充各内容重复总次数!", vbInformation
End Sub