Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2149|回复: 1

[已解决]统计重复数字!!!!

[复制链接]
发表于 2016-6-2 20:56 | 显示全部楼层 |阅读模式
怎么用VBA来统计B列中那些数是重复的?然后把这几个数显示在C列中,求大神赐代码!谢谢!
最佳答案
2016-6-2 21:43
字典去重法
Sub wanao()
    Dim dic As Object, i As Long, arr, a, b As Integer
    Set dic = CreateObject("Scripting.Dictionary")
    arr = Range("b1:b" & Cells(Rows.Count, "b").End(xlUp).Row)
    For i = 1 To UBound(arr, 1)
        dic(arr(i, 1)) = dic(arr(i, 1)) + 1
    Next
    For Each a In dic
        If dic(a) > 1 Then
            b = b + 1
            Cells(b, "c") = a
        End If
    Next
End Sub

工作簿1.rar

41.97 KB, 下载次数: 26

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-6-2 21:43 | 显示全部楼层    本楼为最佳答案   
字典去重法
Sub wanao()
    Dim dic As Object, i As Long, arr, a, b As Integer
    Set dic = CreateObject("Scripting.Dictionary")
    arr = Range("b1:b" & Cells(Rows.Count, "b").End(xlUp).Row)
    For i = 1 To UBound(arr, 1)
        dic(arr(i, 1)) = dic(arr(i, 1)) + 1
    Next
    For Each a In dic
        If dic(a) > 1 Then
            b = b + 1
            Cells(b, "c") = a
        End If
    Next
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-3-29 14:09 , Processed in 0.234368 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表