简体   繁体   English

excel:如果包含文本字符串,如何返回整个单元格

[英]excel : how to return the entire cell if it contains a text string

I have a big column, containing sentences in each row. 我有一栏很大,每一行都包含句子。

I want to return the list of sentences, one after another if they contain a specific word. 我想返回句子列表,如果它们包含特定单词,则一个接一个地返回。 For example, in the following text, which is one column, I want to copy the entire cell if it contains " hath " . 例如,在下面的一栏文字中,如果它包含“ hath ”,我想复制整个单元格。

    Whan that aprill with his shoures soote
    The droghte of march hath perced to the roote,
    And bathed every veyne in swich licour
    Of which vertu engendred is the flour;
    Whan zephirus eek with his sweete breeth
    Inspired hath in every holt and heeth
    Tendre croppes, and the yonge sonne
    Hath in the ram his halve cours yronne,
    And smale foweles maken melodye,
    That slepen al the nyght with open ye
    (so priketh hem nature in hir corages);
    Thanne longen folk to goon on pilgrimages,
    And palmeres for to seken straunge strondes,
    To ferne halwes, kowthe in sondry londes;
    And specially from every shires ende
    Of engelond to caunterbury they wende,
    The hooly blisful martir for to seke,
    That hem hath holpen whan that they were seeke.

thank alot guys 谢谢很多人

Much easier to do with a Filter, or with VBA, but if you must have a formula, you can try this: 使用过滤器或VBA容易得多,但是如果必须具有公式,则可以尝试以下操作:

B1:  =IF(IFERROR(SEARCH("hath",A1),FALSE),A1,"")
B2:  =CONCATENATE(B1,IF(IFERROR(SEARCH("hath",A2),FALSE),A2,""))

Select B2 and fill down to B800. 选择B2并填写至B800。 B800 will contain your concatenated sentences. B800将包含您的级联句子。

If you want to show a newline between each sentence, then try: 如果要在每个句子之间显示换行符,请尝试:

B2:  =CONCATENATE(B1,IF(B1<>CONCATENATE(B1,IF(IFERROR(SEARCH("hath",A2),FALSE),A2,"")),CHAR(10),""),IF(IFERROR(SEARCH("hath",A2),FALSE),A2,""))

Remember to turn on Wrap Text, and you may need to change the font size in order to see all the characters. 记住要打开“自动换行”,并且可能需要更改字体大小才能查看所有字符。

But also remember that, depending on the number of characters in your concatenation, you may run into the length of cell contents limitation. 但也请记住,根据连接中字符的数量,您可能会遇到单元格内容长度的限制。

暂无
暂无

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

相关问题 结合使用VBA和Excel 2007将字符串中存储的数字与包含以文本格式设置的数字的单元格进行比较 - Using VBA with excel 2007 to compare a number stored in a string to a cell which contains a number formatted as text 如果ASCII字符串包含字母或数字,则返回文本 - If ASCII String Contains Letter or Number, Then Return Text 如何从其中写入了单词Text的单元格中返回Excel VBA中“ Text”的等价物? - How to return the equivalent of “Text” in Excel VBA from a cell that has the word Text written in it? excel对另一个单元格包含字符串的所有单元格求和 - excel sum all cells where another cell contains a string Excel宏选择包含字符串的单元格并替换字符 - Excel macro select cell that contains a string and replace a character 如何返回包含string / int变量的字符串 - How to return string that contains string/int variables 在Excel If语句中返回一个数字和文本字符串 - Return a number and text string in Excel If statement 试图从 Excel 中的单元格的开头和结尾提取一串文本模式 - Trying to extract a string of text pattern from the beginning and the end of a cell in Excel VB6:比较Excel中的单元格与文本框中的字符串 - VB6: Comparing a cell from Excel to a string from text box 在 VBA 中,如何检查字符串是否包含在单元格中找到的许多字符串中的任何一个? - In VBA, how to check if a string contains any of many strings found in a cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM