|
楼主 |
发表于 2011-2-19 14:01
|
显示全部楼层
原帖由 humengqiang 于 2011-2-19 11:34 发表
谢谢楼主指点,能不能麻烦您把具体代码写出来并讲解下?我对字典很陌生。谢谢! - Sub cfz()
- Dim i&, Myr&, Arr
- Dim d, k, t
- Set d = CreateObject("Scripting.Dictionary")
- Myr = Sheet1.[a65536].End(xlUp).Row
- Arr = Sheet1.Range("a1:g" & Myr)
- For i = 2 To UBound(Arr)
- d(Arr(i, 3)) = d(Arr(i, 3)) + 1
- Next
- k = d.keys
- t = d.items
- Sheet2.Activate
- Cells.Clear
- [a2].Resize(d.Count, 1) = Application.Transpose(k)
- [b2].Resize(d.Count, 1) = Application.Transpose(t)
- [a1].Resize(1, 2) = Array("姓名", "重复个数")
- For i = UBound(t) To 0 Step -1
- If t(i) = 1 Then
- Cells(i + 2, 1).EntireRow.Delete shift:=xlUp
- End If
- Next
- Set d = Nothing
- End Sub
复制代码 |
|