|
本帖最后由 ykcbf1100 于 2024-2-18 08:34 编辑
代码供参考。。。- Sub ykcbf() '//2024.2.17
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- r = Me.Cells(Rows.Count, 1).End(3).Row
- arr = Me.Range("a1:d" & r)
- ReDim brr(1 To UBound(arr), 1 To 2)
- For i = 3 To UBound(arr)
- s = arr(i, 1)
- If Not d1.exists(s) Then
- d1(s) = Array(arr(i, 1), arr(i, 2))
- Else
- t = d1(s)
- t(1) = IIf(InStr(t(1), arr(i, 2)), t(1), t(1) & "、" & arr(i, 2))
- d1(s) = t
- End If
- For j = 1 To UBound(arr, 2)
- k = arr(i, 4)
- d2(k) = ""
- s = arr(i, 1) & "|" & arr(i, 4)
- d(s) = d(s) + arr(i, 3)
- Next
- Next
- t = d1.items
- For Each k In d1.keys
- m = m + 1
- brr(m, 1) = d1(k)(0)
- brr(m, 2) = d1(k)(1)
- Next
- Me.[g3:z1000] = ""
- Me.[i3].Resize(1, 20) = ""
- Me.[g3].Resize(m, 2) = brr
- Me.[i2].Resize(1, d2.Count) = d2.keys
- arr = Me.[g2].Resize(m + 1, d2.Count + 2)
- For i = 2 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(1, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- Me.[g2].Resize(m + 1, d2.Count + 2) = arr
- Set d = Nothing
- Set d1 = Nothing
- Set d2 = Nothing
- Application.ScreenUpdating = False
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|