- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("文科")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- End With
- ls = 17
- For j = 5 To UBound(arr, 2)
- If InStr("语数英政史地生化", arr(1, j)) <> 0 Then
- Set d(arr(1, j)) = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- If Not d(arr(1, j)).exists(arr(i, 2)) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 2)
- Else
- brr = d(arr(1, j))(arr(i, 2))
- End If
- If Len(arr(i, j)) <> 0 Then
- n = Application.Match(arr(i, j), Array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140))
- If Not IsError(n) Then
- n = 17 - n
- brr(n) = brr(n) + 1
- End If
- brr(ls) = brr(ls) + 1
- End If
- d(arr(1, j))(arr(i, 2)) = brr
- Next
- End If
- Next
- With Worksheets("分数段统计")
- .Cells.Clear
- With .Range("a1")
- .Value = "各分数段各班人数分科统计表"
- .Resize(1, ls).Merge
- With .Font
- .Name = "微软雅黑"
- .Size = 18
- End With
- End With
- r1 = 2
- For Each aa In d.keys
- .Cells(r1, 1) = aa
- With .Cells(r1 + 1, 1).Resize(1, ls)
- .NumberFormatLocal = "@"
- .Value = Array("班级", "140以上", "130-140", "120-130", "110-120", "100-110", "90-100", "80-90", "70-80", "60-70", "50-60", "40-50", "30-40", "20-30", "10-20", "0-10", "实考人数")
- End With
- m = 0
- ReDim crr(1 To d(aa).Count, 1 To ls)
- For Each bb In d(aa).keys
- brr = d(aa)(bb)
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- .Cells(r1 + 2, 1).Resize(UBound(crr), UBound(crr, 2)) = crr
- .Cells(r1 + 2, 1).Resize(UBound(crr), UBound(crr, 2)).Sort key1:=.Cells(r1 + 2, 1), order1:=xlAscending, Header:=xlNo
- With .Cells(r1 + 1, 1).Resize(1 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- r1 = r1 + 2 + UBound(crr) + 1
- Next
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- .Columns(1).Resize(, ls).AutoFit
- End With
- End Sub
复制代码 |