There is a good explanation of how to extract a list of distinct values with an array formula here
The basic formula is this
=IFERROR(INDEX(B$2:B$19, MATCH(0, COUNTIF(D$1:D1, B$2:B$19), 0)),"")
which would give you all of the different values in column B.
With some tweaking you can get
=IFERROR(INDEX(B$2:B$19, MATCH(0, COUNTIF(D$1:D1, IF(A$2:A$19=D$1,B$2:B$19,D$1)), 0)),"")
also as an array formula entered in D2 with "a" in D1 to select just the ones with "a" in column A.
It must be entered with CTRL+shift+enter
The original formula works by
(1) Using COUNTIF to create an array where each element corresponds to a cell in the range B2:B19. If the string in the range B2:B19 is already in a cell above the current cell (initially D2), COUNTIF will put a 1 in the array: if not, it will put a zero.
(2) Using MATCH to find the position of the first zero (corresponding to the next string which hasn't been added to the list) in the array.
(3) Using INDEX to find the string in B2:B19 at that position.
I have chosen to modify it by adding a preliminary step
(0) If the corresponding letter in A2:A19 is "a", use B2:B19 as before - if not, use "a". "a" is already in D1, so it won't be added to the list in column D.
http://www.get-digital-help.com/2009/03/30/how-to-extract-a-unique-list-and-the-duplicates-in-excel-from-one-column/