Dim Teams As Range 'We are saying here that we're going to be making use of a variable "Teams", and it's a Range of cells.
Private Sub CommandButton1_Click()
'This is the "Next Team" button
Cells(1, 1) = Cells(1, 1) + 1 'Performing the operation A1=A1+1
End Sub
Private Sub CommandButton2_Click()
'This is the "Reset" button
Cells(1, 1).Font.Color = RGB(255, 255, 255) 'sets the font colour of A1 to white
Cells(1, 2).Font.Color = RGB(255, 255, 255) 'sets the colour of A2 to white
Cells(1, 1) = 1 'Sets A1 to 1
Set Teams = Worksheets("Data").Range("B2:B20") 'gives us the range we want to fill in with random numbers
For Each Cell In Teams 'for loop - runs over all the cells we want to be random numbers
Cell.Formula = "=RAND()" 'inserts the formula RAND() to all the cells we want to make random
Next 'goes to the next cell in Teams
For Each Cell In Teams 'for loop - runs over all the cells we want to be random numbers
Cell.Value = Cell.Value 'effectively performing paste special - values to the cells we're filling with random numbers. This stops it reseting every time the sheet changes
Next 'goes to the next cell in Teams
Cells(1, 2).Font.Color = RGB(0, 0, 0) 'sets the font colour of A2 to black
Cells(1, 1).Font.Color = RGB(0, 0, 0) 'sets the font colour of A1 to black
End Sub[/pre]
I think the commenting explains everything that's going on with that.
In helper column 2 (in the DATA sheet), instead of just doing a "Rank" function, we use the below:
[code]=IF(ISNA(RANK(B2,INDIRECT("B2:B"&COUNTA($A$1:$A$100)))),0,RANK(B2,INDIRECT("B2:B"&COUNTA($A$1:$A$100))))
What this does:
[code]INDIRECT("B2:B"&COUNTA($A$1:$A$100))
This defines a range of B2 to B-number of team names we've put in.
RANK(B2,RANGE)