I couldn't make much sense of the accepted answer but here is a similar approach. This works in Excel 365, and depends on its dynamic array functionality to work.
Here is the spreadsheet layout I am working with:
I have used spaces to separate the values in the colour list but the solution could be generalised to handle commas etc.
The steps I've used to build the formula needed are:
Group valid list into a single string using TEXTJOIN: TEXTJOIN(",",TRUE,$A$7:$A$9)
Split the Colour cells into columns of words (uses dynamic array functionality). There is a write up on how to do this here: https://www.mrexcel.com/board/excel-articles/split-text-cell-into-columns-of-words.19/ e.g. for A2 this formula produces Black and Red in separate columns
TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2)))
Use FIND to look for the text in each column above, in the valid list
If FIND returns a number (checking with ISNUMBER) return the text, otherwise ""
This is all still in separate columns so now use TEXTJOIN to combine the results together in a comma separated list.
Final formula in B2:
`=TEXTJOIN(",",TRUE,IF(ISNUMBER(FIND(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2))),TEXTJOIN(",",TRUE,$A$7:$A$9))),TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2))),""))`
which can be copied into B3, B4 etc giving final result:
Find()
andLeft()
orRight()
you could seperate it into different cells. – Luuklag