|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("d2:d" & r).ClearContents
- arr = .Range("a2:d" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 2))(0) = d(arr(i, 2))(0) + 1
- brr = Split(arr(i, 3), "、")
- For j = 0 To UBound(brr)
- If Not d(arr(i, 2)).exists(brr(j)) Then
- Set d(arr(i, 2))(brr(j)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 2))(brr(j))(i) = ""
- Next
- Next
- For Each aa In d.keys
- If d(aa)(0) > 1 Then
- ss = ""
- For Each bb In d(aa).keys
- If bb <> 0 Then
- If d(aa)(bb).Count = 1 Then
- d(aa).Remove (bb)
- If d(aa).Count = 0 Then
- d.Remove (aa)
- End If
- End If
- End If
- Next
- Else
- d.Remove (aa)
- End If
- Next
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 2)) Then
- brr = Split(arr(i, 3), "、")
- ss = ""
- For j = 0 To UBound(brr)
- If d(arr(i, 2)).exists(brr(j)) Then
- ss = ss & "、" & brr(j)
- End If
- Next
- arr(i, 4) = Mid(ss, 2)
- End If
- Next
- .Range("a2").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
复制代码 |
|