简体   繁体   English

从单元格中提取值

[英]Extracting values from a cell

I have the following problem. 我有以下问题。 I have cells with values such as this: 我有像这样的值的单元格:

    y
1 Alert, Alert
2 Unresponsive, Alert
3 
4 Alert

I used the following function to try to extract the first word from each cell 我使用以下函数尝试从每个单元格中提取第一个单词

=IF(Y2="", "Blank",LEFT(Y2,(FIND(",",Y2)-1)))

It works BUT I get #value! 它有效,但是我得到了#value! for cells like y4. 对于像y4这样的细胞 If there is no comma, I just want the whole word. 如果没有逗号,我只想要整个单词。

Any thoughts? 有什么想法吗? Thanks for your time! 谢谢你的时间!

The following function will extract the first segment of a list that is delimited with a comma and then a space. 以下函数将提取列表的第一段,该段用逗号和空格定界。

=LEFT(A1,SEARCH(", ",A1)-1)

Where A1 is the cell you want to extract the value from, and the list is delimited with a comma and a space. 其中A1是要从中提取值的单元格,并且列表用逗号和空格分隔。

If you had this in a cell: 如果您在一个单元格中有这个:

y1 Alert, Alert 2 Unresponsive, Alert 3 4 Alert y1警报,警报2无响应,警报3 4警报

This function would return y1 Alert . 该函数将返回y1 Alert

Now to add on your other criteria: display "Blank" if the cell is empty and return the entire word if there is only one entry. 现在添加其他条件:如果单元格为空,则显示“空白”,如果只有一个条目,则返回整个单词。

=IF(A1="","Blank",IFERROR(LEFT(A1,SEARCH(", ",A1)-1),A1))

You can read more about IFERROR as well as SEARCH 您可以阅读有关IFERRORSEARCH的更多信息

也许:

=IF(Y2="","Blank", IFERROR(LEFT(Y2,FIND(",",Y2)-1),Y2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM