- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("总表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:u" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- d(arr(i, 2))(1) = Array(arr(i, 2), arr(i, 5), arr(i, 3), arr(i, 4))
- End If
- If Not d(arr(i, 2)).exists(2) Then
- m = 1
- ReDim brr(1 To 11, 1 To m)
- Else
- brr = d(arr(i, 2))(2)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 11, 1 To m)
- End If
- For j = 1 To 11
- brr(j, m) = arr(i, j + 6)
- Next
- d(arr(i, 2))(2) = brr
- If Not d(arr(i, 2)).exists(3) Then
- m = 1
- ReDim brr(1 To 2, 1 To m)
- Else
- brr = d(arr(i, 2))(3)
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 2, 1 To m)
- End If
- For j = 1 To 2
- brr(j, m) = arr(i, j + 18)
- Next
- d(arr(i, 2))(3) = brr
- Next
- With Worksheets("模板")
- For Each aa In d.keys
- .Range("j1,c5:c7,b9:l18,b22:c31") = ""
- brr = d(aa)(1)
- .Range("j1") = brr(0)
- .Range("c5") = brr(1)
- .Range("c6") = brr(2)
- .Range("c7") = brr(3)
- For k = 2 To 3
- arr = d(aa)(k)
- ReDim brr(1 To UBound(arr, 2), 1 To UBound(arr))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- brr(j, i) = arr(i, j)
- Next
- Next
- .Cells(IIf(k = 2, 9, 22), 2).Resize(UBound(brr), UBound(brr, 2)) = brr
- Next
- On Error Resume Next
- Worksheets(aa).Delete
- .Copy after:=Worksheets(Worksheets.Count)
- ActiveSheet.Name = aa
- Next
- End With
- End Sub
复制代码 |