搜索一张工作表的列并以CSV格式从单独的工作表返回多个匹配项

时间:2019-08-04 20:31:17

标签: google-sheets google-sheets-formula array-formulas google-sheets-query gs-vlookup

我正在尝试搜索Data!A2:A来查找Search!A2:A的多个匹配项。找到匹配项后,从Data!B2:B中获取值,并将其以CSV格式放在Search!B2:B中。

QUERY有效,但是我想以某种方式仅在列顶部输入一次,而不是手动填写。当我尝试将其包装在ARRAYFORMULA中时,我只是将第一个结果复制到该列中。

=JOIN(", ",QUERY(Data!$A$2:$B,"SELECT B WHERE A = '"&A2&"'",0))

这是我的sample spreadsheet

1 个答案:

答案 0 :(得分:1)

=ARRAYFORMULA(REGEXREPLACE(TRIM(IFERROR(VLOOKUP(A2:A, {QUERY(QUERY(Data!A2:B, 
 "select A,count(A) where A is not null group by A pivot B", 0), "select Col1 offset 1", 0),
 TRANSPOSE(QUERY(TRANSPOSE(IF(ISNUMBER(QUERY(QUERY(Data!A2:B, 
 "select count(A) where A is not null group by A pivot B", 0), "offset 1", 0)), 
 QUERY(QUERY(Data!A2:B, 
 "select count(A) where A is not null group by A pivot B", 0), "limit 0", -1)&",", ))
 ,,999^99))}, 2, 0))), ",$", ))

0