Excel查找最后两个下划线之间的文本

时间:2012-11-06 08:59:43

标签: excel excel-formula

我需要一个excel公式来查找excel单元格中最后两个下划线之间的文本:

  

AAA_BBB_CCC_DDDD_E => DDDD
AAA_BBB_CCC_DDD_EEE_E => EEE
AAA_BBB_CCC_DDD_EEE_F_ => F
AAA_BBB_CCC_DDD_EE_GGGGGGGGGG => EE
AAA_BBB_CCC_DDD_EEE_FFF_GGGGGGGGGGGG_H => GGGGGGGGGGGG

我得到的公式是基于最后一个指数: EXCEL LAST INDEX OF

  

=RIGHT(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),LEN(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1))-SEARCH("@",SUBSTITUTE(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),"_","@",LEN(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1))-LEN(SUBSTITUTE(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),"_","")))))

我需要让这个不那么复杂,任何想法?

3 个答案:

答案 0 :(得分:8)

试试这个

=TRIM(LEFT(RIGHT(SUBSTITUTE(H3,"_",REPT(" ",100)),200),100))

请注意,如果任何细分可能超过50个字符,请相应地增加100和200个数字

答案 1 :(得分:2)

克里斯的解决方案非常简洁 - 但是,我也提出了另一种选择。

=MID(A1,1+SEARCH("@", 
     SUBSTITUDE(A1,"_","@",LEN(A1)-1-LEN(SUBSTITUDE(A1,"_","")))),
     SEARCH("@",SUBSTITUDE(A1,"_","@",LEN(A1)-LEN(SUBSTITUDE(A1,"_",""))))-1-
     SEARCH("@",SUBSTITUDE(A1,"_","@",LEN(A1)-1-LEN(SUBSTITUDE(A1,"_","")))))

答案 2 :(得分:2)

这是另一种变化.....

=MID(A1,FIND("^",SUBSTITUTE(A1,"_","^",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-1))+1,SUM(FIND("^",SUBSTITUTE(A1,"_","^",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-{0,1}))*{1,-1})-1)