Maybe like this:
The row above the data is necessary for the formulas.
The formula in B2 and copied down is =IF(COUNTIF(A$1:A1, A2) = 0, ROW() - 1, ROW() - MATCH(2, 1 / (A$1:A1=A2) ) ) - ROW($A$2) + 2
This is an array formula, meaning it MUST be confirmed with Ctrl+Shift+Enter, not just Enter. (With the cursor in the formula bar, hold down Ctrl and Shift, then press Enter.) You'll know you did it correctly if curly braces appear around the formula in the Formula Bar; you cannot type in the braces directly.
Bookmarks