简体   繁体   中英

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 " .

    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:

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. B800 will contain your concatenated sentences.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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