简体   繁体   English

搜索特定文本的行并将其复制到单元格

[英]Search Row for Specific Text and Copy it to Cell

I wonder if anyone can help with this:我想知道是否有人可以提供帮助:

I have a sheet with rows of data.我有一张包含数据行的表格。 Within each row there will be a single occurrence of either 'x' or 'y', among many other entries in other columns.在每一行中,在其他列中的许多其他条目中,将出现一次“x”或“y”。 The string is the only text in the cell.该字符串是单元格中的唯一文本。 No row has both 'x' and 'y'.没有行同时具有“x”和“y”。 I'd like to identify 'x' or 'y' in each row and copy the value to a new column.我想在每一行中识别“x”或“y”并将值复制到新列。

In layman's terms something like;用外行的话来说是这样的;

IF row contains "x" write "x"
  else If row contains "y" write "y"
  else write ""
end

I have managed to get some kind of multi step process going where I use the formula below.我已经设法在使用下面的公式的地方进行了某种多步骤过程。 But it is super clunky and requires many steps, copy, pasting, results etc and won't fly for the guy on Monday.但它超级笨重,需要很多步骤,复制、粘贴、结果等,周一不会为这个人飞行。

=IF(ISNUMBER(SEARCH(substring,text)), "x", "y")

Many thx D多谢 D

You can do nested IF statements.您可以执行嵌套的 IF 语句。 You didn't specify where you want the formula in relation to the data, but if you wanted the result in column A then you could do something like this (assuming you want the result in cell A1 and looking at data in cells in range B1:IV1)...您没有指定与数据相关的公式的位置,但如果您想要 A 列中的结果,那么您可以执行类似的操作(假设您想要单元格 A1 中的结果并查看区域 B1 中的单元格中的数据:IV1)...

=IF(NOT(ISERROR(MATCH("y",$B1:$IV1,0))),"y",IF(NOT(ISERROR(MATCH("x",$B1:$IV1,0))),"x",""))

The basis of this is the MATCH() function.其基础是 MATCH() function。 When a match is NOT found in the range, it returns a #NA error, otherwise it returns the location index of where the first match is.如果在该范围内未找到匹配项,则返回 #NA 错误,否则返回第一个匹配项所在的位置索引。 Since it throws an error when it doesn't find a match, I've wrapped the MATCH in the ISERROR function to turn it into a TRUE/FALSE boolean where TRUE is returned when it is an error and FALSE returned when it's not an error.因为它在找不到匹配项时会引发错误,所以我将 MATCH 包装在 ISERROR function 中,以将其转换为 TRUE/FALSE boolean,其中 TRUE 在错误时返回,在不是错误时返回 FALSE . Since that TRUE/FALSE is opposite of what you're looking for, I wrapped that in the NOT() function to reverse it...returning TRUE when it finds the match of either 'x' or 'y'.由于 TRUE/FALSE 与您正在寻找的相反,我将其包装在 NOT() function 中以反转它......当它找到“x”或“y”的匹配项时返回 TRUE。

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

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