|
- Sub qs() '2024/10/24'前5名可以随数据改变
- Dim arr, i, dic
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet1.Range("a1").CurrentRegion.Value
- crr = Sheet1.Range("a2:m" & Sheet1.Cells(Rows.Count, 1).End(3).Row)
- For j = 4 To UBound(arr, 2)
- s = arr(1, j)
- dic(s) = Application.WorksheetFunction.Transpose(Application.Index(crr, 0, j))
- Next
- k = dic.keys
- For Each k In dic.keys
- tp = ""
- x = dic(k)
- n = UBound(x) - 1
- For m = 1 To UBound(x) '排序名次
- For y = 1 To n
- If x(y) < x(y + 1) Then
- tp = x(y)
- x(y) = x(y + 1)
- x(y + 1) = tp
- End If
- Next
- n = n - 1
- Next
- dic(k) = x
- Next
- ReDim brr(1 To 20000, 1 To 5)
- m = 0
- For j = 4 To UBound(arr, 2)
- For i = 2 To UBound(arr)
- ma1 = dic(arr(1, j))
- For mc = 1 To 5 '前5名可以随数据改变
- mat = mat & "|" & ma1(mc)
- Next
- If InStr(mat, arr(i, j)) > 0 Then
- m = m + 1
- brr(m, 1) = arr(i, 1): brr(m, 2) = arr(i, 2): brr(m, 3) = arr(i, 3)
- brr(m, 4) = arr(1, j): brr(m, 5) = arr(i, j)
- End If
- Next i
- Next j
- Sheet2.Range("a2").Resize(2000, 5) = Empty
- Sheet2.Range("a2").Resize(m, 5) = brr
- Set dic = Nothing
- End Sub
复制代码 |
|