I want to create a VBA function to calculate the rank, like that
But this can't meet my requirements. If I use CALCULATERANKING to calculate the table below it doesn't work. Should I use Lookup or something else to fix it?
VBA Code:
Function CALCULATERANKING(score As Double, list As Range) As Integer
Dim row As Integer
Dim column As Integer
CalculateRanking = 1
For row = 1 To list.Rows.count
If list.Cells(row, 1).Value > score Then
CalculateRanking = CalculateRanking + 1
Else
Exit For
End If
Next
End Function
But this can't meet my requirements. If I use CALCULATERANKING to calculate the table below it doesn't work. Should I use Lookup or something else to fix it?
Student | Score | Rank |
Jason | 98 | 1 |
Peter | 60 | 4 |
Johnny | 70 | 3 |
Amy | 28 | 5 |
Zoe | 85 | 2 |