|
参与一下。。。- Sub ykcbf() '//2024.1.21
- Dim arr, d, sht
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set Sh = ThisWorkbook.Sheets("合并")
- For Each sht In Sheets
- If sht.Name <> Sh.Name Then
- With sht
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- d1(s) = ""
- Next
- For i = 2 To UBound(arr)
- For j = 4 To UBound(arr, 2)
- s = arr(i, 2) & "|" & arr(i, 3)
- If Not d.Exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(arr(1, j)) = arr(i, j)
- Next
- Next
- End If
- Next
- ReDim brr(1 To d.Count, 1 To 3)
- For Each k In d.keys
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = Split(k, "|")(0)
- brr(m, 3) = Split(k, "|")(1)
- Next
- With Sh
- .UsedRange.Clear
- .[a1].Resize(1, d1.Count) = d1.keys
- .[a2].Resize(m, 3) = brr
- arr = .[a1].Resize(m + 1, d1.Count)
- .[a1].Resize(m + 1, d1.Count).Borders.LineStyle = 1
- For i = 2 To UBound(arr)
- For j = 4 To UBound(arr, 2)
- s = arr(i, 2) & "|" & arr(i, 3)
- If d.Exists(s) Then
- arr(i, j) = d(s)(arr(1, j))
- End If
- Next
- With .[a1].Resize(m + 1, d1.Count)
- .Value = arr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- Next
- End With
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|