For a formula we need a title row. The formula needs to start in the second row. So in B2 put:
=IFERROR(INDEX($A$2:$A$9,MATCH(1,INDEX(($A$2:$A$9<>"")*(COUNTIF($B$1:B1,$A$2:$A$9)=0),),0)),"")
This is an array formula. The calculations are exponential and too many of them or too much data will slow the calculations and sometimes stop excel. This usually is in the thousands but be aware.