|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Worksheets("七年级")
- 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
- n = 3
- d1("总分") = n
- For j = 4 To UBound(arr, 2) Step 2
- n = n + 10
- d1(arr(1, j)) = n
- Next
- ls = 2 + d1.Count * 10
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 1)
- Else
- brr = d(arr(i, 1))
- End If
- brr(2) = brr(2) + 1
- s = 0
- For j = 4 To UBound(arr, 2) - 1 Step 2
- n = d1(arr(1, j))
- s = s + arr(i, j)
- brr(n) = brr(n) + arr(i, j)
- If arr(i, j + 1) = "A" Then
- brr(n + 2) = brr(n + 2) + 1
- ElseIf arr(i, j + 1) = "B" Then
- brr(n + 4) = brr(n + 4) + 1
- ElseIf arr(i, j + 1) = "C" Then
- brr(n + 6) = brr(n + 6) + 1
- Else
- brr(n + 8) = brr(n + 8) + 1
- End If
- Next
- brr(3) = brr(3) + s
- If s >= 646 Then
- brr(5) = brr(5) + 1
- ElseIf s >= 570 Then
- brr(7) = brr(7) + 1
- ElseIf s >= 456 Then
- brr(9) = brr(9) + 1
- Else
- brr(11) = brr(11) + 1
- End If
- d(arr(i, 1)) = 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
- d.RemoveAll
- For i = 1 To UBound(crr)
- If Len(crr(i, 2)) <> 0 And crr(i, 2) <> 0 Then
- For j = 3 To UBound(crr, 2) Step 10
- crr(i, j) = Application.Round(crr(i, j) / crr(i, 2), 2)
- crr(i, j + 3) = Application.Round(crr(i, j + 2) / crr(i, 2), 4)
- crr(i, j + 5) = Application.Round(crr(i, j + 4) / crr(i, 2), 4)
- crr(i, j + 7) = Application.Round(crr(i, j + 6) / crr(i, 2), 4)
- crr(i, j + 9) = Application.Round(crr(i, j + 8) / crr(i, 2), 4)
- Next
- End If
- d(crr(i, 3)) = d(crr(i, 3)) + 1
- For j = 3 To UBound(crr, 2)
- If crr(i, j) = 0 Then
- crr(i, j) = Empty
- End If
- Next
- Next
- nn = 1
- kk = d.keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d(mm)
- d(mm) = nn
- nn = nn + ss
- Next
- For i = 1 To UBound(crr)
- crr(i, 4) = d(crr(i, 3))
- Next
- With Worksheets("初一各校各科平均分")
- With .Range("a1")
- .UnMerge
- .Resize(1, UBound(crr, 2)).Merge
- End With
- .UsedRange.Offset(1, 0).Clear
- .Range("a2:b2") = Array("学校", "人数")
- For j = 1 To 2
- .Cells(2, j).Resize(2, 1).Merge
- Next
- n = 3
- For Each aa In d1.keys
- With .Cells(2, n)
- .Value = aa
- .Resize(1, 10).Merge
- End With
- .Cells(3, n).Resize(1, 10) = Array("平均分", "排名", "A人数", "A率", "B人数", "B率", "C人数", "C率", "D人数", "D率")
- n = n + 10
- Next
-
- With .Range("a4").Resize(UBound(crr), UBound(crr, 2))
- .Value = crr
- End With
- With .Range("a2").Resize(2 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- End With
- For j = 3 To UBound(crr, 2) Step 10
- .Columns(j + 3).NumberFormatLocal = "0.00%"
- .Columns(j + 5).NumberFormatLocal = "0.00%"
- .Columns(j + 7).NumberFormatLocal = "0.00%"
- .Columns(j + 9).NumberFormatLocal = "0.00%"
- Next
- .Columns(1).Resize(, UBound(crr, 2)).AutoFit
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|