|
- Sub test()
- Dim r%, i%
- Dim arr, brr, hg#(1 To 50), lk#(1 To 9)
- 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("a2:g" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 5)) Then
- m = 1
- ReDim brr(1 To m)
- Else
- brr = d(arr(i, 5))
- m = UBound(brr) + 1
- ReDim Preserve brr(1 To m)
- End If
- brr(m) = i
- d(arr(i, 5)) = brr
- Next
- With Worksheets("结果")
- .Cells.Clear
- .Cells.PageBreak = xlPageBreakNone
- End With
- r1 = 1
- With Worksheets("模板")
- For i = 1 To UBound(hg)
- hg(i) = .Rows(i).RowHeight
- Next
- For j = 1 To UBound(lk)
- lk(j) = .Columns(j).ColumnWidth
- Next
- For Each aa In d.keys
- brr = d(aa)
- For i = 1 To UBound(brr) Step 20
- For x = 1 To 46 Step 5
- For y = 2 To 7 Step 5
- .Cells(x, y).Resize(4, 1) = Empty
- .Cells(x, y + 2).Resize(4, 1) = Empty
- Next
- Next
- m = 1
- n = 2
- For k = 1 To 20
- If i + k - 1 <= UBound(brr) Then
- .Cells(m, n) = arr(i + k - 1, 4)
- .Cells(m, n + 2) = arr(i + k - 1, 6)
- .Cells(m + 1, n) = arr(i + k - 1, 7)
- .Cells(m + 2, n) = arr(i + k - 1, 5)
- .Cells(m + 3, n) = arr(i + k - 1, 2)
- .Cells(m + 3, n + 2) = arr(i + k - 1, 3)
- End If
- n = n + 5
- If n > 7 Then
- m = m + 5
- n = 2
- End If
- Next
- .Range("a1:i49").Copy Worksheets("结果").Cells(r1, 1)
- r1 = r1 + 50
- With Worksheets("结果")
- .HPageBreaks.Add before:=.Rows(r1)
- End With
- Next
- Next
- End With
- With Worksheets("结果")
- For i = 1 To r1 - 1 Step 50
- For k = 1 To 50
- .Rows(i + k - 1).RowHeight = hg(k)
- Next
- Next
- For j = 1 To UBound(lk)
- .Columns(j).ColumnWidth = lk(j)
- Next
- End With
- End Sub
复制代码 |
|