Explanation
The IFERROR function is designed to trap errors and perform an alternate action when an error is detected. The VLOOKUP function will throw an #N/A error when a value isn’t found.
By nesting multiple VLOOKUPs inside the IFERROR function, the formula allows for sequential lookups. If the first VLOOKUP fails, IFERROR catches the error and runs another VLOOKUP. If the second VLOOKUP fails, IFERROR catches the error and runs another VLOOKUP, and so on.
Explanation
The core of this formula is the IF function, which “filters” the names in the table by color like this:
IF(group=E5,name,""))
The logical test checks each cell in the named range “group” for the color value in E5 (red in this case). The result is an array like this:
{FALSE;FALSE;TRUE;TRUE;FALSE;FALSE;TRUE}
That result is used in turn to filter names from the named range “name”:
{"Matt";"Sally";"Jude";"Aya";"Elle";"Linda";"George"}
For each TRUE, the name survives, for each FALSE, IF returns an empty string ("").
The result of IF looks is this array:
{"";"";"Jude";"Aya";"";"";"George"}
which goes into the TEXTJOIN function as text1.
TEXTJOIN is configured to use a comma as the delimiter, and to ignore empty values. The final result is this text string:
“Jude, Aya, George”
Line break instead of comma
To join matches with a line break instead of a comma, you can adjust the formula like this:
=TEXTJOIN(CHAR(10),TRUE,IF(group=E5,name,""))
The CHAR function returns the code used for a line break. You will also need to enable text wrapping .
Multiple conditions
You can’t use the AND or OR functions in an array formula like this because they only return a single result. You can use boolean logic like this for AND:
=TEXTJOIN(", ",TRUE,IF((condition1)*(condition2),name,""))
Explained in more detail here .