本帖最后由 titi012 于 2024-1-5 18:13 编辑
参与一下。。。
- Function RankTT(Rng As Range, xRng As Range, iNum As Byte) As Long
- Dim Arr, x&, y&, N, M&
- Arr = Rng.Value
- If iNum = 0 Then
- For y = 1 To UBound(Arr) - 1
- For x = 1 To UBound(Arr) - y
- If Arr(x, 1) > Arr(x + 1, 1) Then
- N = Arr(x, 1)
- Arr(x, 1) = Arr(x + 1, 1)
- Arr(x + 1, 1) = N
- End If
- Next x, y
- Else
- For y = 1 To UBound(Arr) - 1
- For x = 1 To UBound(Arr) - y
- If Arr(x, 1) < Arr(x + 1, 1) Then
- N = Arr(x, 1)
- Arr(x, 1) = Arr(x + 1, 1)
- Arr(x + 1, 1) = N
- End If
- Next x, y
- End If
- For x = 1 To UBound(Arr)
- If Arr(x, 1) = xRng.Value Then
- For y = x To UBound(Arr)
- If Arr(y, 1) = Arr(x, 1) Then
- M = y
- Else
- Exit For
- End If
- Next y
- End If
- Next x
- RankTT = M
- End Function
复制代码 |