If you wanted one formula for W5:W8 allowing for Merged Cells then:
W5:
=INDEX($R$5:$R$30,MATCH(1,INDEX(($Q$5:$Q$30=$Y5)*ISNA(MATCH($R$5:$R$30,$W$4:$W4,0)),0),0))
copied down
If for whatever reason you didn't want to use the Alphabet lookup table you could (if you removed the merge from cells W5:W8) use:
W5:
=CHAR(MODE(IF(($D$8:$O$20<>"")*ISNA(MATCH($D$8:$O$20,$W$4:$W4,0)),CODE($D$8:$O$20))))
confirmed with CTRL + SHIFT + ENTER (enter alone would not suffice)
copied down
though the ordering of the duplicates would differ slightly from the first formula (and JBs) - unclear if this is of concern or not.
Bookmarks