|
- Sub test3()
- Dim r%, i%
- Dim arr, brr
- Dim ws As Worksheet
- Dim d(1 To 2) As Object
- For k = 1 To 2
- Set d(k) = CreateObject("scripting.dictionary")
- Next
- For Each ws In Worksheets
- If Left(ws.Name, 2) <> "汇总" Then
- With ws
- xm = Left(ws.Name, Len(ws.Name) - 1)
- lx = Val(Right(ws.Name, 1))
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a4:g" & r)
- If Not d(1).exists(xm) Then
- ReDim brr(1 To 6)
- brr(2) = xm & "幼儿园"
- Else
- brr = d(1)(xm)
- End If
- brr(2 + lx) = arr(UBound(arr), 3)
- d(1)(xm) = brr
- For i = 1 To UBound(arr) - 1
- If Len(arr(i, 4)) > 4 Then
- If Not d(2).exists(arr(i, 4)) Then
- ReDim brr(1 To 8)
- brr(2) = arr(i, 4)
- brr(6) = arr(i, 5)
- brr(7) = arr(i, 6)
- Else
- brr = d(2)(arr(i, 4))
- End If
- brr(2 + lx) = brr(2 + lx) + arr(i, 3)
- d(2)(arr(i, 4)) = brr
- End If
- Next
- End With
- End If
- Next
- For k = 1 To 2
- ls = IIf(k = 1, 6, 8)
- ReDim crr(1 To d(k).Count, 1 To ls)
- ReDim drr(1 To ls)
- drr(1) = "合计"
- m = 0
- For Each aa In d(k).keys
- m = m + 1
- brr = d(k)(aa)
- brr(1) = m
- brr(5) = brr(3) + brr(4)
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- For j = 3 To 5
- drr(j) = drr(j) + brr(j)
- Next
- Next
- With Worksheets("汇总" & k)
- .UsedRange.Offset(3, 0).Clear
- If k = 2 Then
- .Columns(6).NumberFormatLocal = "@"
- End If
- .Range("a4").Resize(UBound(crr), UBound(crr, 2)) = crr
- .Cells(3 + UBound(crr) + 1, 1).Resize(1, UBound(drr)) = drr
- With .Range("a3").Resize(1 + UBound(crr) + 1, ls)
- .Borders.LineStyle = xlContinuous
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Next
- End Sub
复制代码 |
|