
Originally Posted by
Michaelk
GTO thanks for the code, I've tried to run it but it gives an error saying Type mismatch on the line "If rngRaceType.Cells(n, 4).Value = 1 Then", do you know what might cause this error?

Originally Posted by
Michaelk
I got it working, just need to specify the worksheet. But now it does highlight the result but it highlights for RaceA 6.2 as the highest and 4.5 as second highest, but since it's a race time, the highest should be 3.1 instead of 6.2 because shorted time wins. Is there a way to change it?
Okay, it seems you got it working, I am assumed you changed to RANK?
Oops! My bad on the order, of course low ET is likely to be the winner... Changing the last arg to -1 seems to work.
rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 3).FormulaArray = _
"=RANK(" & rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 1).Address(0, 0) & _
"," & rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 1).Address(0, 0) & ",-1)"

Originally Posted by
Michaelk
I've just notice another problem. The above code sort the Race type into ascending order, but I'm having other columns eg competitor name etc which has to be with the Race type and time, so I can't just sort the Race type into ascending order. And also I will be sorting the Time into ascending order aswell, so the above code won't work for me. What I have done so far is:
No, it only temporarily sorts to put the race types (or heats?) together to use RANK on the now contiguous range. It may have seemed like the sort was permanent when the code broke, but if you follow it through, you'll see that we put some row numbers in a helper column first, so it can be sorted back at the end.
You did not mention "...other columns..." before, which of course would be handy to know.
If you reduce vbide and step through the code, you can see we now insert the helper columns, do the work, and delete the helper columns. Hopefully that won't glitch any formulas.
I see you are getting help elsewheres, but here is what I came up with:
In a Standard Module:
[VBA]Option Explicit
Sub RateIt_02()
Dim rngRaceType As Range
Dim n As Long
Dim lCount As Long
Dim lRowStart As Long
'// Ensure that activesheet is a real worksheet //
If TypeName(ActiveSheet) = "Worksheet" Then
If ActiveSheet.Type = xlWorksheet Then
With ActiveSheet
Set rngRaceType = Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
Else
Exit Sub
End If
Else
Exit Sub
End If
rngRaceType.Offset(, 2).Resize(, 2).Columns.EntireColumn.Insert xlShiftToRight
Set rngRaceType = rngRaceType.Resize(, 4)
With rngRaceType
.Columns(3).Formula = "=row()"
.Columns(3).Value = .Columns(3).Value
.Sort .Columns(1).Cells(1), xlAscending, , , , , , xlNo
lCount = 1
lRowStart = 1
For n = 2 To UBound(rngRaceType.Value, 1)
Do While rngRaceType.Cells(n, 1).Value = rngRaceType.Cells(n - 1, 1).Value _
And n <= UBound(rngRaceType.Value, 1)
lCount = lCount + 1
n = n + 1
Loop
rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 3).FormulaArray = _
"=RANK(" & rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 1).Address(0, 0) & _
"," & rngRaceType.Cells(lRowStart, 1).Resize(lCount).Offset(, 1).Address(0, 0) & ",-1)"
lCount = 1
lRowStart = n
Next
For n = 1 To UBound(rngRaceType.Value, 1)
If rngRaceType.Cells(n, 4).Value = 1 Then
rngRaceType.Cells(n, 1).Interior.ColorIndex = 4
ElseIf rngRaceType.Cells(n, 4).Value = 2 Then
rngRaceType.Cells(n, 1).Interior.ColorIndex = 6
End If
Next
'// Clear first, because of the array formula //
.Columns(4).Clear
.Sort .Columns(3).Cells(1), xlAscending, , , , , , xlNo
.Columns(3).Resize(, 2).EntireColumn.Delete
End With
End Sub[/VBA]