搜索多列并返回顶部单元格值

时间:2019-05-14 03:35:23

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

我有一个INDEX公式,该公式将从行的第一个单元格获取一个值,在另一张纸的多列中搜索匹配项,并在找到匹配项时返回相应的标题行值。

问题是我必须手动复制此公式,以使其适用于每一行。但更重要的是,如果我编辑公式或创建新行,则需要确保将修改应用于每行。我更希望在该列顶部具有一个适用于下面所有单元格的公式。

=INDEX(subTaskCategories!$C$1:$J$1,MAX(IF(subTaskCategories!$C$2:$J=A2,COLUMN(subTaskCategories!$C$2:$J)-COLUMN(A2)-1)))

INDEX的替代方法是什么?当找到匹配项也可以将其包装在ARRAYFORMULA中时,它将搜索多列并返回标头?

My sheet在subTaskData!C2

1 个答案:

答案 0 :(得分:1)

粘贴在 B2 单元格中:

=ARRAYFORMULA(IFERROR(VLOOKUP(REGEXEXTRACT(C2:C, "^~ (.*) ~$"), 
 TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(
 QUERY(TRANSPOSE(IF(INDIRECT("taskCategories!C2:"&ADDRESS(ROWS(taskCategories!A1:A), 
 COLUMNS(taskCategories!A1:AA1), 4))<>"", "♥"&INDIRECT("taskCategories!C2:"&
 ADDRESS(ROWS(taskCategories!A1:A), COLUMNS(taskCategories!A1:AA1), 4))&"♦"&
 INDIRECT("taskCategories!C1:"&ADDRESS(1, COLUMNS(taskCategories!A1:AA1), 4)), ))
 , , 999^99)), , 999^99), "♥")), "♦")), 2, 0)))

0


粘贴在 C2 单元格中:

=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(
 QUERY(TRANSPOSE(IF(INDIRECT("subtaskCategories!C2:"&ADDRESS(ROWS(subTaskCategories!A1:A), 
 COLUMNS(subTaskCategories!A1:AA1), 4))<>"", "♥"&INDIRECT("subtaskCategories!C2:"&
 ADDRESS(ROWS(subTaskCategories!A1:A), COLUMNS(subTaskCategories!A1:AA1), 4))&"♦"&
 INDIRECT("subtaskCategories!C1:"&ADDRESS(1, COLUMNS(subTaskCategories!A1:AA1), 4)), ))
 , , 999^99)), , 999^99), "♥")), "♦")), 2, 0)))

0