Fotis, it's better to use =COUNTIF(B$2:B2,B2) since you don't depend on order in column.

But no matter of that, your solution probably won't work because it assuming that y is in last instance of unique word, and that don't need to be true.
(i.e. out n in A3)