Function RANK2(value As Double, R As Range, order As Integer) As Integer
Dim a(1000) As Double
Dim n As Integer
Dim i As Integer
Dim k As Integer
Dim tam As Double
n = 0
For i = 1 To R.Rows.Count
If n > 0 Then
For k = 1 To n
If R.Cells(i, 1) = a(k) Then
GoTo tiep
End If
Next k
End If
n = n + 1
a(n) = R.Cells(i, 1)
tiep:
Next i
For i = 1 To n - 1
For k = i + 1 To n
If a(i) > a(k) Then
tam = a(i)
a(i) = a(k)
a(k) = tam
End If
Next k
Next i
For i = 1 To n
If value = a(i) Then
If order = 1 Then
RANK2 = i
Else
RANK2 = n - i + 1
End If
End If
Next i
End Function
Không có nhận xét nào:
Đăng nhận xét