I'm trying to dynamically extract the string between 2 characters in Excel using a formula (no text to columns). The sample data is:
US - Blue Widgets - Net
UK - Green - Grass
UAE - Red - Apples
* Note that the data doesn't have fixed length
I tried using a formula, but I think I'm missing something because that also returns the string after the last -.
Formula:
=TRIM(LEFT(SUBSTITUTE(MID(A2,FIND("|",SUBSTITUTE(A2,"-","|",1))+1,LEN(A2)),"_",REPT(" ",LEN(A2))),LEN(A2)))
what this returns is:
Blue Widgets - Net
Green - Grass
Red - Apples
here's what I'd like it to return:
Blue Widgets
Green
Red
解决方案
Try this:
=TRIM(MID(A2, 6, FIND("-",A2,6) - FIND("-",A2) - 2))
If hard coded 6 is not ok, you can replace it with FIND("-", A2) + 1.