我有数据和分配是使用公式将其排列在一行中。例如:
Question) Find all the persons living in New York or Delhi?
Sample: New York/Delhi ________ ___________ ___________
Question) Find all the persons living in Delhi and earning more than 1200?
Sample: Delhi/1200 ______ ________ _________ _______
请注意:此数据需要在一行中
答案 0 :(得分:0)
我假设这个名字总是一个字。因此,单元格中的第一个单词是 Name ,最后一个单词是 Income ,名称和收入之间的所有内容都是 City 。
嗯,如果您可以将文本拆分为三个不同的列Name
,City
和Income
,然后使用这些列来获得所需的结果,那就更好了。
要从单元格中获取 名称 ,请在Cell B2
=LEFT(A2,(FIND(" ",A2,1)-1))
然后 城市 在Cell C2
=TRIM(MID(A2,FIND(" ",A2,1)+1,FIND("|",SUBSTITUTE(A2," ","|",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))))-FIND(" ",A2,1)-1))
对于 收入 ,在Cell D2
中输入公式
=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),LEN(A2)))
现在在Cell B12
中输入以下公式以获取第一个查询的结果,即
查找居住在纽约或德里的所有人
=IFERROR(INDEX($B$2:$B$9, SMALL(IF(($C$2:$C$9="New York")+($C$2:$C$9="Delhi"), ROW($B$2:$B$9)-1, ""), COLUMN(B$1)-COLUMN($A$1))),"")
这是一个数组公式,所以按 Ctrl + Shift + Enter 提交它。根据需要拖动/复制。
在Cell B14
中输入以下公式进行第二次查询,即
查找居住在德里并且收入超过1200的所有人
=IFERROR(INDEX($B$2:$B$9, SMALL(IF(($C$2:$C$9="Delhi")*($D$2:$D$9>1200), ROW($B$2:$B$9)-1, ""), COLUMN(B$1)-COLUMN($A$1))),"")
这是一个数组公式。根据需要拖动/复制。见图片以供参考。
如果您不想在不同的列中断文本,则可以使用以下公式来获得所需的结果。这些公式非常丑陋但会给你你想要的东西。
在Cell B12
中输入以下公式
=IFERROR(INDEX(LEFT($A$2:$A$9,(FIND(" ",$A$2:$A$9,1)-1)), SMALL(IF((TRIM(MID($A$2:$A$9,FIND(" ",$A$2:$A$9,1)+1,FIND("|",SUBSTITUTE($A$2:$A$9," ","|",LEN($A$2:$A$9)-LEN(SUBSTITUTE($A$2:$A$9," ",""))))-FIND(" ",$A$2:$A$9,1)-1))="New York")+(TRIM(MID($A$2:$A$9,FIND(" ",$A$2:$A$9,1)+1,FIND("|",SUBSTITUTE($A$2:$A$9," ","|",LEN($A$2:$A$9)-LEN(SUBSTITUTE($A$2:$A$9," ",""))))-FIND(" ",$A$2:$A$9,1)-1))="Delhi"), ROW($A$2:$A$9)-1, ""), COLUMN(B$1)-COLUMN($A$1))),"")
并在Cell B14
输入
=IFERROR(INDEX(LEFT($A$2:$A$9,(FIND(" ",$A$2:$A$9,1)-1)), SMALL(IF((TRIM(MID($A$2:$A$9,FIND(" ",$A$2:$A$9,1)+1,FIND("|",SUBSTITUTE($A$2:$A$9," ","|",LEN($A$2:$A$9)-LEN(SUBSTITUTE($A$2:$A$9," ",""))))-FIND(" ",$A$2:$A$9,1)-1))="Delhi")*(TRIM(RIGHT(SUBSTITUTE($A$2:$A$9," ",REPT(" ",LEN($A$2:$A$9))),LEN($A$2:$A$9)))*1>1200), ROW($A$2:$A$9)-1, ""), COLUMN(B$1)-COLUMN($A$1))),"")
以上两个公式都是数组公式,所以按 Ctrl + Shift + 输入。根据需要拖动/复制。