this, longer, non-array formula in Sheet1!B10 will produce the same result:
=IFERROR(INDEX('2nd'!$A$1:$A$11,SMALL(INDEX(('2nd'!$C$1:$C$11="d")*(ROW('2nd'!$C$1:$C$11)-MIN(ROW('2nd'!$C$1:$C$11))+1),0),COUNTIF('2nd'!$C$1:$C$11,"<>"&"d")+ROW($A1))),"-")
if you were to capture D or E or P in another cell, such as Sheet1!B9, then the formula could be (formula is not case-sensitive):
=IFERROR(INDEX('2nd'!$A$1:$A$11,SMALL(INDEX(('2nd'!$C$1:$C$11=$B$9)*(ROW('2nd'!$C$1:$C$11)-MIN(ROW('2nd'!$C$1:$C$11))+1),0),COUNTIF('2nd'!$C$1:$C$11,"<>"&$B$9)+ROW($A1))),"-")
Bookmarks