|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 成绩分析()
Application.ScreenUpdating = False
Dim ar As Variant, arr As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Set sh = Sheets("成绩")
r = sh.Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "成绩表为空!": End
With Sheets("名次段")
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If y = 1 Then MsgBox "名次段为空!": End
rr = .Range(.Cells(1, 1), .Cells(1, y))
arr = .Range("a4:m6")
End With
For j = 2 To 13
dc(arr(1, j)) = j
Next j
ar = sh.Range("a1:n" & r)
With Sheets("分析数据")
.UsedRange.Borders.LineStyle = 0
.UsedRange = Empty
For j = 3 To 14
k = 1: d.RemoveAll
ReDim br(1 To UBound(ar), 1 To UBound(rr, 2) + 3)
For jj = 1 To UBound(rr, 2)
br(1, jj + 1) = rr(1, jj)
Next jj
br(1, 1) = "班级"
br(1, UBound(br, 2) - 1) = "[ " & ar(1, j) & " ]" & "普本上线人数"
br(1, UBound(br, 2)) = "[ " & ar(1, j) & " ]" & "一本上线人数"
lh = dc(ar(1, j))
pb = arr(2, lh)
yb = arr(3, lh)
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = d(ar(i, 1))
If t = "" Then
k = k + 1
d(ar(i, 1)) = k
t = k
br(k, 1) = ar(i, 1)
End If
If ar(i, j) <> "" Then
If IsNumeric(ar(i, j)) Then
mc = Application.Rank(ar(i, j), sh.Range(sh.Cells(2, j), sh.Cells(r, j)))
For s = 1 To UBound(rr, 2) - 1
ks = Val(Split(rr(1, s), "-")(0))
js = Val(Split(rr(1, s), "-")(1))
If mc >= ks And mc <= js Then
br(t, s + 1) = br(t, s + 1) + 1
'Exit For
End If
Next s
If ar(i, j) >= pb Then br(t, UBound(br, 2) - 1) = br(t, UBound(br, 2) - 1) + 1
If ar(i, j) >= yb Then br(t, UBound(br, 2)) = br(t, UBound(br, 2)) + 1
End If
End If
End If
Next i
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 2
If rs = 3 Then rs = 1
.Cells(rs, 1) = ar(1, j)
.Cells(rs + 1, 1).Resize(k, UBound(br, 2)) = br
x = rs + k + 1
For i = rs + 2 To x - 1
.Cells(i, UBound(rr, 2) + 1) = Application.Sum(.Range(.Cells(i, 2), .Cells(i, UBound(rr, 2))))
Next i
.Cells(x, 1) = "总计"
For jj = 2 To UBound(rr, 2) + 1
.Cells(x, jj) = Application.Sum(.Range(.Cells(rs + 2, jj), .Cells(x - 1, jj)))
Next jj
.Cells(rs + 1, 1).Resize(k + 1, UBound(br, 2)).Borders.LineStyle = 1
Next j
.Columns("a:v").AutoFit
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|