|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
写个最简单的各科三分统计,这个没有考虑学生缺考的问题。楼主的问题确实复杂,我算是抛个砖吧。
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- For Each ws In Worksheets(Array("七年级", "八年级", "九年级"))
- With ws
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- ReDim Preserve arr(1 To UBound(arr), 1 To UBound(arr, 2) + 1)
- arr(1, UBound(arr, 2)) = "全科"
- For i = 2 To UBound(arr)
- For j = 5 To UBound(arr, 2) - 1
- arr(i, j) = Val(arr(i, j))
- arr(i, UBound(arr, 2)) = arr(i, UBound(arr, 2)) + arr(i, j)
- Next
- Next
- ReDim brr(1 To 4, 1 To UBound(arr, 2) - 4)
- For j = 5 To UBound(arr, 2)
- brr(1, j - 4) = arr(1, j)
- crr = Application.Index(arr, 0, j)
- brr(2, j - 4) = Application.Large(Application.Index(arr, 0, j), Round((UBound(arr) - 1) * 0.6, 0))
- brr(3, j - 4) = Application.Large(Application.Index(arr, 0, j), Round((UBound(arr) - 1) * 0.2, 0))
- brr(4, j - 4) = Application.Large(Application.Index(arr, 0, j), Round((UBound(arr) - 1) * 0.8, 0))
- Next
- d(ws.Name) = brr
- End With
- Next
- On Error Resume Next
- Worksheets("各科三分").Delete
- On Error GoTo 0
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- With ws
- .Name = "各科三分"
- With .Range("a1")
- .Value = "及格分、优秀分、关爱分取值"
- .Resize(1, 12).Merge
- With .Font
- .Name = "微软雅黑"
- .Size = 16
- End With
- End With
- i1 = 2
- For Each aa In d.keys
- brr = d(aa)
- .Cells(i1, 1).Resize(1, 2) = Array("年级", "项目")
- With .Cells(i1 + 1, 1)
- .Value = aa
- .Resize(3, 1).Merge
- End With
- .Cells(i1 + 1, 2).Resize(3, 1) = [{"及格分";"优秀分";"关爱分"}]
- .Cells(i1, 3).Resize(UBound(brr), UBound(brr, 2)) = brr
- With .Cells(i1, 1).Resize(4, 2 + UBound(brr, 2))
- .Borders.LineStyle = xlContinuous
- .BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
- End With
- i1 = i1 + 4
- Next
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "各科三分计算完毕!"
-
- End Sub
复制代码 |
评分
-
5
查看全部评分
-
|