|
Sub 提取前n名()
Dim ar As Variant
Dim br()
w = InputBox("请输入提取的名次", "前几名", "30")
If w = "" Then End
With ActiveSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "数据源为空!": End
ar = .Range("a1:j" & r)
.[m1].CurrentRegion.Offset(2) = Empty
y = 12
For j = 3 To 9
n = 0
ReDim br(1 To UBound(ar), 1 To 4)
zd = Application.Large(Application.Index(ar, 0, j), Val(w))
For i = 2 To UBound(ar)
If ar(i, j) <> "" Then
If IsNumeric(ar(i, j)) Then
If ar(i, j) >= zd Then
n = n + 1
br(n, 1) = n
br(n, 2) = ar(i, 1)
br(n, 3) = ar(i, 2)
br(n, 4) = ar(i, j)
End If
End If
End If
Next i
For i = 1 To n
For s = i + 1 To n
If br(i, 4) < br(s, 4) Then
For jj = 1 To 4
k = br(i, jj)
br(i, jj) = br(s, jj)
br(s, jj) = k
Next jj
End If
Next s
br(i, 1) = i
Next i
.Cells(1, y) = ar(1, j)
.Cells(3, y).Resize(n, UBound(br, 2)) = br
.Cells(3, y).Resize(n, UBound(br, 2)).Borders.LineStyle = 1
y = y + 4
Next j
End With
MsgBox "ok!"
End Sub |
|