简体   繁体   English

Excel:在单元格中找到一个单词,然后返回前一个单词和找到的单词

[英]Excel: find a word in a cell, then return the preceding word and the found word

This is a slightly different take on a previous question I asked. 这与我之前提出的问题稍有不同。 I tried to modify the great advice I received but couldn't quite get there. 我试图修改我收到的很棒的建议,但还不能完全解决。

I am looking to find text in a cell (not case specific), then return the preceding word plus the found text. 我正在寻找一个单元格中的文本(不区分大小写),然后返回前一个单词加上找到的文本。 I prefer a formulaic solution (over a macro). 我更喜欢公式化的解决方案(而不是宏)。

Sample cell contents include the following where I'm looking for " TRUCK ": 示例单元格内容包括以下我正在寻找的“ TRUCK ”:

"This is a test dump TRUCK like it 54" - I want " dump TRUCK " “这是一个像54一样的测试转储卡车 ”-我要“ 转储卡车

"This is pick-up Truck forgot 346 I like" - I want " pick-up Truck " “这是我喜欢的忘了346的皮卡车 ”-我要“ 皮卡车

I tried some combo of the Mid() function but wasn't quite getting it: 我尝试了Mid()函数的一些组合,但并没有完全理解:

=MID(B2,(FIND("Truck",B2,1)-1),FIND(" ",B2,FIND("Truck",B2,1)-1)-FIND("Truck",B2,1)+1)

Thanks for the help! 谢谢您的帮助!

=TRIM(RIGHT(SUBSTITUTE(LEFT(B2,SEARCH(" Truck ",B2)+5)," ",REPT(" ",99)),199))

LEFT(B2,SEARCH(" Truck ",B2)+5) gets the " This is a test dump TRUCK " part. LEFT(B2,SEARCH(" Truck ",B2)+5)获得“ This is a test dump TRUCK ”部分。

Then SUBSTITUTE( ^ ," ",REPT(" ",99)) gets: 然后SUBSTITUTE( ^ ," ",REPT(" ",99))得到:

This                                                                                                   is                                                                                                   a                                                                                                   test                                                                                                   dump                                                                                                   TRUCK

and =TRIM(RIGHT( ^ ,199)) gets the last 2 words from the above and removes the extra spaces. =TRIM(RIGHT( ^ ,199))从上面获得最后2个单词,并删除多余的空格。

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

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