Return an Occurrence of a Value
For the n-th occurrence of a value in a column, returns the associated (in the same row) value in a second (value) column of the n-th occurrence of the value in a third (lookup) column.
Try the following array formula (AltShift+Enter) in cell E2 and copy down.
=IFERROR(INDEX(B$2:B$7,SMALL(IF(A$2:A$7=D2,ROW(A$2:A$7)-ROW(INDEX(A$2:A$7,1,1))+1),COUNTIF(D$2:D2,D2))),"")
Formula Evaluations for Cell E2
IFERROR "b"
INDEX "b"
B$2:B$7 {"b",1,2,5,10,20}
SMALL 1
IF {1,2,3,FALSE,FALSE,FALSE}
A$2:A$7=D2 {TRUE,TRUE,TRUE,FALSE,FALSE,FALSE}
A$2:A$7 {"a","a","a","b","b","c"}
D2 "a"
ROW(A$2:A$7)-ROW(INDEX(A$2:A$7;1;1))+1 {1,2,3,4,5,6}
ROW(A$2:A$7)-ROW(INDEX(A$2:A$7;1;1)) {0,1,2,3,4,5}
ROW(A$2:A$7) {2,3,4,5,6,7}
ROW(INDEX(A$2:A$7;1;1))+1 {3}
ROW(INDEX(A$2:A$7;1;1)) {2}
INDEX(A$2:A$7;1;1) "a"
COUNTIF(D$2:D2;D2) 1