|
- Sub test3()
- Dim r%, i%
- Dim arr, brr, crr()
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("统计")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:w" & r)
- End With
- n = 2
- For i = 1 To UBound(arr)
- If Not d1.exists(arr(i, 1)) Then
- d1(arr(i, 1)) = n
- n = n + 6
- End If
- Next
- ls = 1 + d1.Count * 6
- For i = 1 To UBound(arr)
- rq = DateSerial(Year(arr(i, 6)), Month(arr(i, 6)), 1)
- If Not d.exists(rq) Then
- ReDim brr(1 To ls)
- brr(1) = rq
- Else
- brr = d(rq)
- End If
- n = d1(arr(i, 1))
- brr(n) = brr(n) + 1
- brr(n + 1) = brr(n + 1) + arr(i, 18)
- brr(n + 2) = brr(n + 2) + arr(i, 19)
- brr(n + 3) = brr(n + 3) + arr(i, 20)
- brr(n + 4) = brr(n + 4) + arr(i, 21)
- brr(n + 5) = brr(n + 5) + arr(i, 18) + arr(i, 19) + arr(i, 20) + arr(i, 21)
- d(rq) = brr
- Next
- ReDim crr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- With Worksheets("样式")
- .Cells.Clear
- .Range("a3").Resize(UBound(crr), 1).NumberFormatLocal = "yyyy年m月"
- With .Range("a1")
- .Value = "工厂名"
- .Resize(2, 1).Merge
- End With
- n = 2
- For Each aa In d1.keys
- With .Cells(1, n)
- .Value = aa
- .Resize(1, 6).Merge
- End With
- .Cells(2, n).Resize(1, 6) = Array("计数", "外观", "组装", "包装", "机能", "合计")
- n = n + 6
- Next
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)) = crr
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)).Sort key1:=.Range("a3"), order1:=xlAscending, Header:=xlNo
- With .Range("a1").Resize(2 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|