|
- Sub test()
- Dim r%, i%, m%, n%
- Dim arr, brr
- Dim ws As Worksheet
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- n = 6
- For Each ws In Worksheets(Array("2021", "2022"))
- With ws
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:k" & r)
- For i = 1 To UBound(arr)
- xm = arr(i, 3) & "+" & arr(i, 5) & "+" & arr(i, 11)
- If Not d.exists(xm) Then
- ReDim brr(1 To 17)
- brr(2) = arr(i, 2)
- brr(3) = arr(i, 3)
- brr(4) = arr(i, 4)
- brr(5) = arr(i, 5)
- Else
- brr = d(xm)
- End If
- For j = 6 To UBound(arr, 2)
- brr(n + j - 6) = arr(i, j)
- Next
- d(xm) = brr
- Next
- End With
- n = n + 6
- Next
- With Worksheets("合并汇总")
- .UsedRange.Offset(1, 0).Clear
- With .Range("a2").Resize(d.Count, 17)
- .Value = Application.Transpose(Application.Transpose(d.items))
- .Borders.LineStyle = xlContinuous
- End With
- End With
- End Sub
复制代码 |
|