我一直在尝试为下一个问题写一个公式,但是我从来没有正确。所以:
我必须在2D数组中找到前n个值,并记下与该值相关的行和列的名称(没有重复项!)。例如,这是一个数组:
A B C D E F
1 Aron Jamie Matt Taylor Zedd
2 Aron - 5 7 6 8
3 Jamie 5 - 2 4 3
4 Matt 7 2 - 15 12
5 Taylor 6 4 15 - 26
6 Zedd 8 3 12 26 -
应使用公式记录的内容,在此示例中,前3个值以及与这些值相关的名称:
A B C
Taylor Zedd 26
Taylor Matt 15
Matt Zedd 12
谢谢!
使用您的数据,运行以下宏:
Sub dural()
Dim i As Long, j As Long, K As Long
i = 3: j = 2: K = 1
Do
Cells(K, "G") = Cells(i, 1)
Cells(K, "H") = Cells(1, j)
Cells(K, "I") = Cells(i, j)
K = K + 1
j = j + 1
If Cells(i, j).Value = "-" Then
j = 2
i = i + 1
If i = 7 Then Exit Do
End If
Loop
Range("G1:I10").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("I1:I10") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("G1:I10")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
将在G,H和I列中为您提供完整的结果。
选择前三行以获取前三项结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句