|
Sub 提取前w名()
Dim ar As Variant, br As Variant
Dim i As Long
Dim arr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
w = InputBox("请输入要提取的名次", "名次", "10")
If w = "" Then Exit Sub
mc = Val(w)
With Sheets("理科成绩")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:ad" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(ar(i, 1)) = ""
End If
Next i
Sheets("单科前十名(样表)").UsedRange = Empty
For j = 3 To 24 Step 3
If Trim(ar(2, j)) <> "" Then
m = 0: y = 1: sl = 0
ReDim arr(1 To UBound(ar), 1 To UBound(ar, 2))
m = m + 1
arr(m, 1) = Sheets("理科成绩").Cells(1, j)
arr(2, 1) = "班级名次"
For Each k In d.keys
n = 0: y = y + 1: sl = sl + 1
m = m + 1
arr(2, y) = k & "班"
m = 2
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If ar(i, 1) = k Then
n = n + 1
For jj = 1 To UBound(ar, 2)
br(n, jj) = ar(i, jj)
Next jj
End If
Next i
For i = 1 To n
For s = i + 1 To n
If IsNumeric(br(i, j)) And IsNumeric(br(s, j)) Then
If br(i, j) < br(s, j) Then
For ss = 1 To UBound(br, 2)
kk = br(i, ss)
br(i, ss) = br(s, ss)
br(s, ss) = kk
Next ss
End If
End If
Next s
Next i
For i = 1 To n
If i <= mc Then
If Trim(br(i, j)) <> "" Then
m = m + 1
If sl = 1 Then arr(m, 1) = i
arr(m, y) = br(i, j)
End If
End If
Next i
Next k
With Sheets("单科前十名(样表)")
rs = .Cells(Rows.Count, 1).End(xlUp).Row + 2
If rs = 3 Then
rs = 1
Else
rs = rs
End If
.Cells(rs, 1).Resize(m, y) = arr
.Cells(rs + mc + 2, 1) = "均分"
For jj = 2 To y
.Cells(rs + mc + 2, jj) = Application.Sum(.Range(.Cells(rs + 2, jj), .Cells(rs + 11, jj))) / 10
Next jj
End With
End If
Next j
End Sub
|
评分
-
1
查看全部评分
-
|