Say I have the following table (A much smaller one than the one I actually have):
[TABLE="width: 500"]
<tbody>[TR]
[TD]Japan[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]44[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]RacerC[/TD]
[TD]154[/TD]
[/TR]
[TR]
[TD]RacerD[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]RacerE[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]China[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]165[/TD]
[/TR]
[TR]
[TD]Romania[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]RacerC[/TD]
[TD]19[/TD]
[/TR]
[TR]
[TD]RacerD[/TD]
[TD]24[/TD]
[/TR]
[TR]
[TD]RacerE[/TD]
[TD]130[/TD]
[/TR]
</tbody>[/TABLE]
I want to go through the list and delete all other times except the top 3 for each country and the corresponding racer.
My idea was having a column with =COUNTIF() and therefore displaying:
[TABLE="width: 500"]
<tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
Therefore if <2 then ignore and skip this particular case.
I was thinking a way to skip between cases... I guess if you know the number of racers you can compare all their times and then rank the top 3 but I dont know how to do that.... I've had a dig at it but got nowhere - any advice on how/where to go would be v appreciated!
Thanks.
Code so far:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Japan[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]44[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]RacerC[/TD]
[TD]154[/TD]
[/TR]
[TR]
[TD]RacerD[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]RacerE[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]China[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]165[/TD]
[/TR]
[TR]
[TD]Romania[/TD]
[TD]Time[/TD]
[/TR]
[TR]
[TD]RacerA[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]RacerB[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]RacerC[/TD]
[TD]19[/TD]
[/TR]
[TR]
[TD]RacerD[/TD]
[TD]24[/TD]
[/TR]
[TR]
[TD]RacerE[/TD]
[TD]130[/TD]
[/TR]
</tbody>[/TABLE]
I want to go through the list and delete all other times except the top 3 for each country and the corresponding racer.
My idea was having a column with =COUNTIF() and therefore displaying:
[TABLE="width: 500"]
<tbody>[TR]
[TD]5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[/TR]
[TR]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
Therefore if <2 then ignore and skip this particular case.
I was thinking a way to skip between cases... I guess if you know the number of racers you can compare all their times and then rank the top 3 but I dont know how to do that.... I've had a dig at it but got nowhere - any advice on how/where to go would be v appreciated!
Thanks.
Code so far:
Code:
Private Sub fixIT()
Dim lr As Long
Dim impCell As Range
'refering to the countif column
impCell = Range("C1")
'refering to the Column that has all the time values.
lr = Range("B" & Rows.Count).End(xlUp).Row
Range("B1").Select
For j = 1 To lr
'If impCell.value < 3 then goto Line 1
'If ActiveCell.Value is not in top 3 then
ActiveCell.Delete shift:=xlUp
ActiveCell.Offset(0, -1).Delete shift:=xlUp
Line1:
Else
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub