|
这个问题只需要一个字典即可解决。
字典套字典也是可以做的。- Sub lqxs()
- Dim Arr, i&, x$, y$, j&, jj&, Brr(1 To 5000, 1 To 3)
- Dim d, k, t, kk, tt, aa, n&
- Set d = CreateObject("Scripting.Dictionary")
- Sheet2.Activate
- Arr = [a1].CurrentRegion
- For i = 2 To UBound(Arr)
- x = Arr(i, 1): y = Arr(i, 2)
- If d.exists(x) = False Then Set d(x) = CreateObject("Scripting.Dictionary")
- d(x)(y) = d(x)(y) + Arr(i, 3)
- Next
- k = d.keys: t = d.items
- For i = 0 To UBound(k)
- kk = t(i).keys: tt = t(i).items
- For j = 0 To UBound(kk)
- tt(j) = Left(tt(j), Len(tt(j)) - 1)
- If InStr(tt(j), ",") Then
- aa = Split(tt(j), ",")
- For jj = 0 To UBound(aa)
- n = n + 1
- Brr(n, 1) = k(i): Brr(n, 2) = kk(j): Brr(n, 3) = aa(jj)
- Next
- Else
- n = n + 1
- Brr(n, 1) = k(i): Brr(n, 2) = kk(j): Brr(n, 3) = tt(j)
- End If
- Next
- Next
- [f2].Resize(n, 3) = Brr
- End Sub
复制代码 |
|