【问题标题】:excel : how to return the entire cell if it contains a text stringexcel:如果包含文本字符串,如何返回整个单元格
【发布时间】:2014-09-14 18:17:40
【问题描述】:

我有一个很大的列,每一行都包含句子。

如果句子包含特定单词,我想一个接一个地返回句子列表。 例如,在下面的一列文本中,如果它包含 "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.

非常感谢大家

【问题讨论】:

  • 我想自动化它。所以我需要一个公式。例如,如果它们在 A1:A800 范围内包含“hath”,我想将所有句子连接在一起。

标签: string excel text


【解决方案1】:

使用过滤器或 VBA 更容易,但如果你必须有一个公式,你可以试试这个:

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

选择 B2 并向下填写到 B800。 B800 将包含您的连接句子。

如果你想在每个句子之间显示一个换行符,那么试试:

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

记得开启文字换行,您可能需要更改字体大小才能看到所有字符。

但也请记住,根据串联中的字符数,您可能会遇到单元格内容长度的限制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2012-08-05
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 2022-10-01
    • 2022-09-23
    相关资源
    最近更新 更多