|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("镇成绩统计表")
- c = .Cells(3, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a3").Resize(1, c)
- For j = 4 To UBound(arr, 2)
- d1(arr(1, j)) = j
- Next
- End With
- ls = c
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:g" & r)
- End With
- For i = 2 To UBound(arr)
- If d1.exists(arr(i, 1)) Then
- n = d1(arr(i, 1))
- For j = 5 To UBound(arr, 2)
- If Len(arr(i, j)) <> 0 Then
- If Not d.exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 2)).exists(arr(1, j)) Then
- ReDim brr(1 To 5, 1 To ls)
- brr(1, 1) = arr(i, 2)
- brr(1, 2) = arr(1, j)
- brr(1, 3) = "平均分"
- brr(2, 3) = "优良率"
- brr(3, 3) = "及格率"
- brr(4, 3) = "低分率"
- Else
- brr = d(arr(i, 2))(arr(1, j))
- End If
- brr(1, n) = brr(1, n) + arr(i, j)
- brr(5, n) = brr(5, n) + 1
- If arr(i, j) >= 80 Then
- brr(2, n) = brr(2, n) + 1
- End If
- If arr(i, j) >= 60 Then
- brr(3, n) = brr(3, n) + 1
- End If
- If arr(i, j) <= 40 Then
- brr(4, n) = brr(4, n) + 1
- End If
- d(arr(i, 2))(arr(1, j)) = brr
- End If
- Next
- End If
- Next
- With Worksheets("镇成绩统计表")
- .UsedRange.Offset(3, 0).Clear
- r = 4
- For Each aa In d.keys
- r1 = r
- For Each bb In d(aa).keys
- brr = d(aa)(bb)
- For i = 1 To 5
- For j = 4 To UBound(brr, 2) - 1
- brr(i, UBound(brr, 2)) = brr(i, UBound(brr, 2)) + brr(i, j)
- Next
- Next
- For j = 4 To UBound(brr, 2)
- If brr(5, j) <> 0 And Len(brr(5, j)) <> 0 Then
- brr(1, j) = Application.Round(brr(1, j) / brr(5, j), 2)
- brr(2, j) = Application.Round(brr(2, j) / brr(5, j), 4) * 100
- brr(3, j) = Application.Round(brr(3, j) / brr(5, j), 4) * 100
- brr(4, j) = Application.Round(brr(4, j) / brr(5, j), 4) * 100
- End If
- Next
- .Cells(r, 1).Resize(4, UBound(brr, 2)) = brr
- .Cells(r, 2).Resize(4, 1).Merge
- r = r + 4
- Next
- .Cells(r1, 1).Resize(d(aa).Count * 4, 1).Merge
- Next
- With .Range("a3:n" & r - 1)
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 9
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|