If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

huangapple go评论59阅读模式
英文:

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

问题

我想尽量自动化我的电子表格。在一个列中,我有超过30个变量,这些变量总是缩写,并附带其他附加信息,而在下一个列中,我希望它显示缩写的全称。例如:

列1             列2
xxx-a-xxx       苹果
xxx-b-xxx       香蕉
xxx-c-xxx       蔓越莓
xxx-d-xxx       龙眼
xxx-e-xxx       茄子

我希望有一个公式可以检查所有我的变量,并在列2中返回正确的单词。正如我提到的,我有超过30个变量,我希望确保它检查-a-,-b-,-c-,-d-,-e-等,并且找到哪个就返回该缩写的指定单词。

我首先尝试了:

=IF([@Asset]="*-a-*","apple","")

但这根本不起作用。

然后我搜索了一下,并尝试了:

=IF(ISNUMBER(SEARCH("-a-",A1)),"apple")

但无法找到一种添加其他变量的方法。

我想做的事情是否可能?

提前感谢。

为了回答一些问题,创建一个新的列会破坏其目的,因为信息是以“建筑代码-单位缩写-单位编号”的形式输入到表中的。

所以,举个例子,表格会看起来像这样:

列1               列2

ABC-EF-001         排气扇
ABC-EF-002         排气扇
ABC-FU-001         熔炉
ABC-FU-002         熔炉
ABC-GEN-001        发电机

感谢大家提供的解决方案。非常感谢!

英文:

I am looking to automate as much of my spreadsheet as possible. In one column I have over 30 variables that are always abbreviated with other additional information and in the next column I want it to say the full word for the abbreviation. For Example:

Column 1      Column 2
xxx-a-xxx     Apple
xxx-b-xxx     Banana
xxx-c-xxx     Cranberry
xxx-d-xxx     Dragon Fruit
xxx-e-xxx     Egg Plant

I want an equation that can check for all my variables and return the correct word in column 2, and as mentioned I have over 30 variables, I want to make sure it checks for -a-,-b-,-c-,-d-,-e-... and whichever one it finds it will it will return the designated word for that abbreviation.

I first tried:

=IF([@Asset]="*-a-*","apple","")

But this did not work at all.
Then googled around and tried:

=IF(ISNUMBER(SEARCH("-a-",A1)),"apple")

But could not find a way to add additional variables.

Is what I'm looking to do even possible?

Thanks in advance.

To answer some questions, creating a new column would defeat the purpose as the information is input into the table as "Building code-unit abbreviation-unit number"

So as another example table will look like

Column 1           Column 2

ABC-EF-001         Exhaust Fan
ABC-EF-002         Exhaust Fan
ABC-FU-001         Furnace
ABC-FU-002         Furnace
ABC-GEN-001        Generator 

Thank you to everyone for your solutions. Very much appreciated!

答案1

得分: 6

创建一个查找表:

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

然后使用FILTER函数:

=FILTER($F$2:$F$6,ISNUMBER(SEARCH($E$2:$E$6,A2)))

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


或者如果没有FILTER函数:

=INDEX($F$2:$F$6,MATCH(TRUE,INDEX(ISNUMBER(SEARCH($E$2:$E$6,A2)),),0))

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

英文:

Create a lookup table:

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

Then use FILTER:

=FILTER($F$2:$F$6,ISNUMBER(SEARCH($E$2:$E$6,A2)))

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


Or if one does not have FILTER:

=INDEX($F$2:$F$6,MATCH(TRUE,INDEX(ISNUMBER(SEARCH($E$2:$E$6,A2)),),0))

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

答案2

得分: 3

=CHOOSE(TOCOL(1/ISNUMBER(SEARCH({"-a-","-b-","-c-","-d-","-e-"},A2))*{1,2,3,4,5},3),"苹果","香蕉","蔓越莓","火龙果","茄子")

旧版的Excel:
=INDEX({"苹果","香蕉","蔓越莓","火龙果","茄子"},AGGREGATE(15,6,{1,2,3,4,5}/(ISNUMBER(SEARCH({"-a-","-b-","-c-","-d-","-e-"},A2))),1))

英文:

It's better to list them and use a lookup variation as in Scott's reply, but this could be used:

=CHOOSE(TOCOL(1/ISNUMBER(SEARCH({"-a-","-b-","-c-","-d-","-e-"},A2))*{1,2,3,4,5},3),"Apple","Banana","Cranberry","Dragon Fruit","Egg Plant")

It searches the cell for the array of search strings and multiplies the result with the position of the CHOOSE function to return.

Older version of Excel:
=INDEX({"Apple","Banana","Cranberry","Dragon Fruit","Egg Plant"},AGGREGATE(15,6,{1,2,3,4,5}/(ISNUMBER(SEARCH({"-a-","-b-","-c-","-d-","-e-"},A2))),1))

答案3

得分: 2

以下是翻译好的部分:

在 OP 更新查询后编辑的帖子:

如前面在评论中已经提到并在答案中发布的,使用一个<kbd>查找表</kbd>确实会更容易。以下是我想出来的方法,使用<kbd>XLOOKUP( )</kbd>与<kbd>TEXTSPLIT( )</kbd>,还有另一种使用<kbd>LOOKUP( )</kbd>函数的替代版本,供那些不使用MS365的人使用,我希望它也能正常工作。


If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• 单元格<kbd>B2</kbd>中使用的公式:

=XLOOKUP("-"&CHOOSECOLS(TEXTSPLIT(A2,"-"),2)&"-",$E$2:$E$9,$F$2:$F$9)


或者,

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

• 单元格<kbd>C2</kbd>中使用的公式:

=LOOKUP(2,1/SEARCH($E$2:$E$9,A2),$F$2:$F$9)


或者,

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• 单元格<kbd>B2</kbd>中使用的公式 --> 区分大小写。

=LOOKUP(2,1/FIND($E$2:$E$9,A2),$F$2:$F$9)


另一种方法是使用<kbd>XLOOKUP( )</kbd>与<kbd>TEXTBEFORE( )</kbd>和<kbd>TEXTAFTER( )</kbd>。

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• 单元格<kbd>B2</kbd>中使用的公式:

=XLOOKUP("-"&TEXTBEFORE(TEXTAFTER(A2:A11,"-"),"-")&"-",E2:E9,F2:F9)


英文:

Edited Post After OP's Updated Query:

As already mentioned above in comments and posted in answer also, using a <kbd>LOOKUP TABLE</kbd> definitely makes it easier. Here is what I came up with, using <kbd>XLOOKUP( )</kbd> with <kbd>TEXTSPLIT( )</kbd> and another alternative version with <kbd>LOOKUP( )</kbd> function for those not using MS365, I hope it works as well.


If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• Formula used in cell <kbd>B2</kbd>

=XLOOKUP(&quot;-&quot;&amp;CHOOSECOLS(TEXTSPLIT(A2,&quot;-&quot;),2)&amp;&quot;-&quot;,$E$2:$E$9,$F$2:$F$9)

Or,

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

• Formula used in cell <kbd>C2</kbd>

=LOOKUP(2,1/SEARCH($E$2:$E$9,A2),$F$2:$F$9)

Or,

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• Formula used in cell <kbd>B2</kbd> --> For case-sensitive.

=LOOKUP(2,1/FIND($E$2:$E$9,A2),$F$2:$F$9)

Another way using <kbd>XLOOKUP( )</kbd> with <kbd>TEXTBEFORE( )</kbd> & <kbd>TEXTAFTER( )</kbd>

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text


• Formula used in cell <kbd>B2</kbd>

=XLOOKUP(&quot;-&quot;&amp;TEXTBEFORE(TEXTAFTER(A2:A11,&quot;-&quot;),&quot;-&quot;)&amp;&quot;-&quot;,E2:E9,F2:F9)

答案4

得分: 1

=XLOOKUP(INDEX(TEXTSPLIT([@[Column 1]],"-"),2),Table5[Code],Table5[Fruit],"")

英文:

If "A" text is in "A" cell, return "X" text, If "B" text is in "A" Cell return "Y" Text, If "C" Text is in "A" cell, return "Z" Text

=XLOOKUP(INDEX(TEXTSPLIT([@[Column 1]],"-"),2),Table5[Code],Table5[Fruit],"")

If the data in Column 1 uses a consistent format (each code is in the same position and you're using a "-" as a separator), you can use this same formula for any code by simply changing the value in the INDEX formula (currently "2") and pointing your XLOOKUP to the appropriate table and columns.

答案5

得分: 0

=IF(FIND("a",A19,1)>0,1,0)

所以find()返回一个数字,显示找到字符的位置,你可能需要在iferror()中包装find()。

之后,你可以转到查找表或类似的地方。

英文:

I used the following for a slightly different application:

=IF(FIND("a",A19,1)>0,1,0)

So find() returns a number showing the position the character is found, you might need to wrap find() in iferror() though.

After that you can go to a lookup table or similar.

huangapple
  • 本文由 发表于 2023年8月4日 02:45:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定