extract text between 2 tags

S

SteveC

Cell A1 contains the text below.

In Cell B1, how do extract all the text between <status> and </status> so it
returns "error"

another example, how do I extract all the text between <comment> and
</comment>?

generally, how do I extract text that lies between 2 tags?

thanks a lot...



<apple2>
<status>error</status>
<ack></ack>
<errortype>Can't enter BTC - Not currently short</errortype>
<comment><![CDATA[You can't enter an order to Buy To Close (BTC) because
you do not have a short position in BHP.
If you want to enter a BTC, make it conditional on a
not-yet-executed STO order. ]]></comment>
</apple2>
 
L

Luke M

I believe this will work:

=LEFT(MID(A2,FIND("<status>",A2)+LEN("<status>"),999),FIND("</status>",MID(A2,FIND("<status>",A2)+LEN("<status>"),999))-1)

You can replace the "<status>" & "</status>" with other texts, if deisred,
or simply change them to a cell reference.
 
S

SteveC

thanks works great!

Luke M said:
I believe this will work:

=LEFT(MID(A2,FIND("<status>",A2)+LEN("<status>"),999),FIND("</status>",MID(A2,FIND("<status>",A2)+LEN("<status>"),999))-1)

You can replace the "<status>" & "</status>" with other texts, if deisred,
or simply change them to a cell reference.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


SteveC said:
Cell A1 contains the text below.

In Cell B1, how do extract all the text between <status> and </status> so it
returns "error"

another example, how do I extract all the text between <comment> and
</comment>?

generally, how do I extract text that lies between 2 tags?

thanks a lot...



<apple2>
<status>error</status>
<ack></ack>
<errortype>Can't enter BTC - Not currently short</errortype>
<comment><![CDATA[You can't enter an order to Buy To Close (BTC) because
you do not have a short position in BHP.
If you want to enter a BTC, make it conditional on a
not-yet-executed STO order. ]]></comment>
</apple2>
 

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