Quoted By:
Put "1" in A1 and this in A2 on downwards:
=IF(ISERROR(INDEX($B1:B$1,MATCH(B2,$B1:B$1,0))),MAX($A$1:A1)+1,INDEX($A$1:A1,MATCH(B2,$B$1:B1,0)))
This checks to see if B2's value exists anywhere above it in column B, and depending on that it either returns the highest previous index +1 or the index number of the cell it matches.