- Sub NewLst()
- Dim Dic As Object, Itm
- Dim Arr, Ary, k%, i%, m%
- Arr = [A1].CurrentRegion
- Set Dic = CreateObject("Scripting.Dictionary")
- For k = 2 To UBound(Arr)
- Dic(Arr(k, 1)) = Dic(Arr(k, 1)) + 1
- Next
- Ary = Dic.items
- k = Application.Max(Ary)
- ReDim Ary(1 To Dic.Count, 1 To (2 + k * 2))
- For Each Itm In Dic
- i = i + 1
- m = 2
- For k = 2 To UBound(Arr)
- If Arr(k, 1) = Itm Then
- m = m + 1
- Ary(i, 1) = Arr(k, 1): Ary(i, 2) = Arr(k, 2)
- Ary(i, m) = Arr(k, 3): Ary(i, m + 1) = Arr(k, 4)
- m = m + 1
- End If
- Next
- Next
- Dic.RemoveAll
- [F5].Resize(i, UBound(Ary, 2)) = Ary
- End Sub
复制代码 |