Extract between Pipe symbol

T

Tony S.

Can someone please tell me if it is possible to write a formula that would
extract all the text that exists between the vertical bar symbol "|".

Example in the following Cell A1 contains:
W213FR|BADC12GW34-14|SPACER, DEG

I want to extract only "BADC12GW34-14" and put it in another cell, say B1.
Thanks!
 
F

Fred Smith

This seems to work:

=MID(A1,FIND("|",A1)+1,FIND("|",MID(A1,FIND("|",A1)+1,99))-1)

Hopefully someone else will come up with a shorter version.

Regards,
Fred.
 
F

FiluDlidu

Enter the following in cell B1:


=MID(A1,FIND("|",A1)+1,FIND("|",A1,FIND("|",A1)+1)-FIND("|",A1)-1)
 
C

Chip Pearson

If the text to test is in A1, you can use

=MID(A1,(FIND("|",A1,1)+1),(FIND("|",A1,(FIND("|",A1,1)+1)+1))-(FIND("|",A1,1)+1))

This will return a #VALUE error if there are not two | characters in
A1. You can test for that condition with the expanded formula

=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"|","")) <>2,NA(),
MID(A1,(FIND("|",A1,1)+1),(FIND("|",A1,(FIND("|",A1,1)+1)+1))-(FIND("|",A1,1)+1)))



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
T

Tony S.

Fred & FiluDlidu,

Your answers were exactly what I needed. Thank you!
Chip, a special thanks to you for going the extra mile with your error
trapping example. Great stuff!

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top