=LET(HeaderMatch1,MATCH(E1,StockTable___2[#Headers],0),
HeaderMatch2,MATCH(E2,StockTable___2[#Headers],0),
ForHeaders,TOROW(MATCH(D5:K5,StockTable___2[#Headers],0),2),
Filt1,CHOOSECOLS(FILTER(StockTable___2,(ISNUMBER(SEARCH("*"&G1&"*",INDEX(StockTable___2,,HeaderMatch1))))+(ISNUMBER(SEARCH("*"&G2&"*",INDEX(StockTable___2,,HeaderMatch1))))),ForHeaders),
Filt2,CHOOSECOLS(FILTER(StockTable___2,(ISNUMBER(SEARCH("*"&G1&"*",INDEX(StockTable___2,,HeaderMatch2))))+(ISNUMBER(SEARCH("*"&G2&"*",INDEX(StockTable___2,,HeaderMatch2))))),ForHeaders),
IF(COUNTA(E1:E2)=0,"No Search Columns",IF(AND(E1<>"",E2=""),Filt1,IF(AND(E2<>"",E1=""),Filt2,VSTACK(Filt1,Filt2)))))

I wonder if they work with dynamic array functions?