Search code examples
excelfunctionexcel-formulaexcel-2010trim

How to extract text before special character from string in Excel?


I have below text on column A1:

100-This_Is_My-Test_200

Looking to get output as below in column B1:

100-This_Is_My-Test

so basically it needs to remove text starting from last _ (underscore)

I tried below:

=TRIM(RIGHT(SUBSTITUTE(A1,"_",REPT(" ",LEN(A1))),LEN(A1)))  

Output: 200

=TRIM(LEFT(SUBSTITUTE(A1,"_",REPT(" ",LEN(A1))),LEN(A1)))  

Output: 100-This


Solution

  • =LEFT(A1,FIND("}}}",SUBSTITUTE(A1,"_","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))))-1)
    

    enter image description here