|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
附上代码。。。- Sub ykcbf() '//2024.3.20
- Dim arr, d
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- With Sheets("原始")
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- arr = .[a1].Resize(r, 4)
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- d1(s) = ""
- s = arr(i, 2) & "|" & arr(i, 3)
- d2(s) = ""
- s = arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 1)
- d(s) = arr(i, 4)
- Next
- t = d.items
- ReDim brr(1 To d2.Count, 1 To 2)
- For Each k In d2.keys
- If k <> Empty Then
- m = m + 1
- brr(m, 1) = Split(k, "|")(0)
- brr(m, 2) = Split(k, "|")(1)
- End If
- Next
- With Sheets("目的")
- .UsedRange.Offset(1, 2).ClearContents
- .Rows(1).NumberFormatLocal = "@"
- .[c1].Resize(1, d1.Count) = d1.keys
- .[a2].Resize(m, 2) = brr
- arr = .[a1].Resize(m + 1, 2 + d1.Count)
- For i = 2 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(1, j)
- If d.Exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- .Columns(1).NumberFormatLocal = "@"
- .[a1].Resize(m + 1, 2 + d1.Count) = arr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|