|
2次字典去重 也可以首先对整行去重了做A列去重就行- Sub 去重重排() '字典用法一
- Dim i&, j&, arr, brr, dic1, dic2
- arr = Range([A1], [b65536].End(xlUp)) 'AB列
- Set dic1 = CreateObject("scripting.dictionary")
- '--先取得A列关键字对应项
- For i = 1 To UBound(arr)
- If dic1.exists(arr(i, 1)) Then '字典中已存在则条目累计
- dic1(arr(i, 1)) = dic1(arr(i, 1)) & "," & arr(i, 2)
- Else
- dic1(arr(i, 1)) = arr(i, 2) '字典中不存在加入
- End If
- Next
- '--对A列关键字的B列项目去重
- arr = dic1.keys
- Set dic2 = CreateObject("scripting.dictionary")
- For i = 0 To UBound(arr)
- brr = Split(dic1(arr(i)), ",") '取出A关键字对应项目
- For j = 0 To UBound(brr) 'B列子项去重
- If Not dic2.exists(brr(j)) Then dic2(brr(j)) = brr(j)
- Next
- dic1(arr(i)) = Join(dic2.keys, ",") '去重重组
- dic2.RemoveAll
- Next
- [E:F] = ""
- [E1].Resize(dic1.Count) = Application.Transpose(dic1.keys) '导出关键字
- [F1].Resize(dic1.Count) = Application.Transpose(dic1.items) '导出条目
- End Sub
复制代码
数据去重重排.zip
(15.89 KB, 下载次数: 21)
|
|