|
代码供参考!
- Sub 拆分2()
- Dim Arr, Brr(), Crr(), Bt, Ms$
- Dim i%, x%, n%, s%, n1%, n2%, a%, b&
- Dim LastRow%, m
- Application.ScreenUpdating = False
- Arr = Sheets("数据源").[a1].CurrentRegion
- Bt = Array("单位名称3", "警号", "数量", "单位名称3", "警号", "数量")
- Ms = Sheets("丝织警号").Cells(1, 1)
- ReDim Brr(1 To UBound(Arr), 1 To 6)
- For i = 2 To UBound(Arr)
- If Arr(i, 2) = Ms Then
- x = x + 1
- Brr(x, 1) = Arr(i, 5)
- Brr(x, 2) = Arr(i, 9)
- Brr(x, 3) = Arr(i, 11)
- End If
- Next i
- For i = 1 To x - 1
- n1 = i: n = i
- Do While Brr(n1, 1) = Brr(n + 1, 1)
- n = n + 1
- s = s + Brr(n, 3)
- Brr(n, 1) = ""
- Loop
- s = s + Brr(n1, 3)
- Brr(n1, 1) = Brr(n1, 1) & ":" & s
- i = n
- s = 0
- Next i
- If Brr(x, 1) <> Brr(x - 1, 1) Then Brr(x, 1) = Brr(x, 1) & ":" & Brr(x, 3)
- ReDim Crr(1 To x, 1 To 6)
- a = 0: b = 0: n2 = 0
- For i = 1 To x
- a = a + 1
- Crr(a, b + 1) = Brr(i, 1): Crr(a, b + 2) = Brr(i, 2): Crr(a, b + 3) = Brr(i, 3)
- If a Mod 55 = 0 Then
- If b = 3 Then
- n2 = n2 + 1
- a = n2 * 55
- b = 0
- Else
- a = n2 * 55
- b = 3
- End If
- End If
- Next i
- LastRow = 55 * (x \ 110) + x Mod 110
- With Sheets("丝织警号")
- .[a1].Resize(1, 6).Merge
- .Range("a2:f9999").Clear
- .[a2].Resize(1, 6) = Bt
- .[a3].Resize(LastRow, 6) = Crr
- With .[a1].Resize(LastRow + 2, 6)
- .Borders.LineStyle = 1
- With .Font
- .Size = 10
- .Name = "宋体"
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .RowHeight = 14.5
- m = .Address
- End With
- With .Rows(1)
- .Font.Size = 12
- .Font.Bold = True
- .RowHeight = 40
- End With
- With .Rows(2)
- .Font.Size = 12
- .Font.Bold = True
- .RowHeight = 22
- End With
- For i = 56 To LastRow Step 55 '分页设置 和 打印区域
- '设置很耗时间演示中我就注释掉了
- .Rows(i).PageBreak = 1
- Next i
- .PageSetup.PrintArea = m
- .Columns.AutoFit
- End With
- Sheets("丝织警号").Activate
- Set Dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|