2

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

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can get help from the following link, its pretty useful,,

http://www.mrexcel.com/forum/excel-questions/444266-extract-string-between-two-characters.html

Comments

0

I used this and worked.

=IF(ISERROR(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(MID(A3,FIND("|",SUBSTITUTE(A3,"-","|",1))+1,LEN(A3)),"-",REPT(" ",LEN(A3))),LEN(A3)))," ","")),"",SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(MID(A3,FIND("|",SUBSTITUTE(A3,"-","|",1))+1,LEN(A3)),"-",REPT(" ",LEN(A3))),LEN(A3)))," ",""))

you will get:

Blue Widgets
Green
Red

is you want to get the last part, I mean the string after the second "-" use this

=IF(ISERROR(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(MID(A3,FIND("|",SUBSTITUTE(A3,"-","|",2))+1,LEN(A3)),"-",REPT(" ",LEN(A3))),LEN(A3)))," ","")),"",SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(MID(A3,FIND("|",SUBSTITUTE(A3,"-","|",2))+1,LEN(A3)),"-",REPT(" ",LEN(A3))),LEN(A3)))," ",""))

you will get:

Net
Grass
Apples

Best regads.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.