简体   繁体   English

Excel-找到特定文本后在括号之间提取文本

[英]Excel - extracting text between parentheses after finding certain text

I have tried searching for an answer but can't seem to find the exact solution. 我曾尝试寻找答案,但似乎找不到确切的解决方案。 I am trying to extract text between two parentheses starting at a certain string of text. 我正在尝试从某个文本字符串开始的两个括号之间提取文本。 Ie the cell contains the following – ABC (12.3%) DEFGH (18.1%) IJKL (17.2%). 即该单元格包含以下内容-ABC(12.3%)DEFGH(18.1%)IJKL(17.2%)。 I want to have a reference cell saying "ABC" then the cell below return the % number in between parentheses following ABC. 我想有一个引用单元格说“ ABC”,然后下面的单元格在ABC之后的括号之间返回%数字。

The current formula I am using is the below, where G6 is the full line of text and I5 is the reference cell "ABC": =MID(G6,FIND(I5,G6)+FIND("(",G6),FIND("(",G6)+1+FIND(")",G6)-FIND("(",G6)-7) 我正在使用的当前公式如下,其中G6是文本的完整行,I5是参考单元格“ ABC”:= MID(G6,FIND(I5,G6)+ FIND(“(”,G6),FIND ( “(”,G6)+ 1 + FIND( “)”,G6)-find( “(”,G6)-7)

This will work when the Input is 3 characters long (ABC), but won't work when the string text is a different length. 当输入法是3个字符长(ABC)时,此方法将起作用,但是当字符串文本的长度不同时,该方法将不起作用。

Can someone help me create a formula where I can pull the % number regardless of how many characters there are? 有人可以帮我创建一个公式,不管有多少个字符,都可以提取%的数字吗?

With the big string in A1 and ABC in B1 , try: 使用A1中的大字符串和B1中的 ABC ,尝试:

=LEFT(MID(A1,FIND(B1,A1)+LEN(B1)+2,9999),FIND(")",MID(A1,FIND(B1,A1)+LEN(B1)+2,9999))-1)

在此处输入图片说明

what is going on: 到底是怎么回事:

The core of the formula: MID(D1,FIND(E1,D1)+LEN(E1)+2,9999) discards the front end of the string and returns: 12.3%) DEFGH (18.1%) IJKL (17.2%) . 公式的核心: MID(D1,FIND(E1,D1)+LEN(E1)+2,9999)丢弃字符串的前端并返回: 12.3%) DEFGH (18.1%) IJKL (17.2%)

The enclosing part discards the closing parens and every that follows. 封闭部分将丢弃封闭括号,并且随后的每个封闭括号都将被丢弃。

If you are trying to separate all the different strings, then it might be best to split it up. 如果您尝试分离所有不同的字符串,则最好将其拆分。

String Splitting 字符串分割

Cell A1: 'The current String'
Cell B1:    =SEARCH("(",A2)
Cell C1:    =SEARCH(")",A2)
Cell D1:    =MID($A$2,1,B2-1)
Cell E1:    =MID($A$2,B2+1,(C2-B2)-1)
Cell F1:    =SEARCH("(",A2,12)
Cell G1:    =SEARCH(")",A2,12)
Cell H1:    =MID($A$2,C2+1,(F2-C2)-1)
Cell I1:    =MID($A$2,F2+1,(G2-F2)-1)
Cell J1:    =SEARCH("(",A2,26)
Cell K1:    =SEARCH(")",A2,26)
Cell L1:    =MID($A$2,G2+1,(J2-G2)-1)
Cell M1:    =MID($A$2,J2+1,(K2-J2)-1)
  • B1 & C1 will search for the first appearance of "(" & ")". B1和C1将搜索“(“&”)”的第一个外观。

  • D1 & E1 will then use those numbers in B1 & C1 to find the text you're searching for. 然后D1和E1将使用B1和C1中的这些数字来查找您要搜索的文本。

  • F1 & G1 will search for the second appearance of "(" & ")" F1和G1将搜索“(”和“)”的第二个外观

  • H1 & I1 will then use those numbers in F1 & G1 to find the text you're searching for. 然后,H1和I1将使用F1和G1中的这些数字来查找您要搜索的文本。

  • J1 & K1 will search for the third appearance of "(" & ")" J1和K1将搜索“(”和“)”的第三个外观

  • L1 & M1 will then use those numbers in J1 & K1 to find the text you're searching for. 然后,L1和M1将使用J1和K1中的那些数字来查找您要搜索的文本。

This process breaks it down for every piece of string. 此过程将其分解为每个字符串。 In the picture I attached I also added additional fields for trimming the results to eliminate any blank spaces. 在所附的图片中,我还添加了其他字段,用于修剪结果以消除任何空白。

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

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