Extract A String Between Two Characters

theaudioguy

New Member
Joined
Jan 27, 2010
Messages
27
I'm stuck. I need a formula to extract data from between two characters.

For Example, In A1 I have this: COMP_PROG_v1_ABCD_01

I want to extract the value between the 3rd and 4th "_"'s. The number of "_"'s will be consistent but not the # of characters between them. My brain is tired of thinking. Thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Beaten 2 it, but another option
=TRIM(MID(SUBSTITUTE($A$1,"=",REPT(" ",100)),SEARCH(",",","&SUBSTITUTE($A$1,"=",REPT(" ",100)),COLUMN(A1)*100-99),100))
=TRIM(MID(SUBSTITUTE($A$1,",",REPT(" ",100)),SEARCH("=",SUBSTITUTE($A$1,",",REPT(" ",100)),COLUMN(A2)*100-99)+1,100))

One more question, please:

Any idea why if the text part has more characters - the formula doesn't work anymore?

For example, for:


<tbody>
[TD="width: 1394"]ABCDEFG-01=1,ABCDEFG-02=10,ABCDEFG-03=10,ABCDEFG-04=10,ABCDEFG-05=10,ABCDEFG-06=10,ABCDEFG-07=10,ABCDEFG-08=10,ABCDEFG-09=10,ABCDEFG-10=10,ABCDEFG-11=10,ABCDEFG-12=10
[/TD]

</tbody>

It repeats ABCDEFG-09 twice.

Thank you!
 
Upvote 0
You need to increase the number of spaces the formula adds.
=TRIM(MID(SUBSTITUTE($A$3,"=",REPT(" ",500)),SEARCH(",",","&SUBSTITUTE($A$3,"=",REPT(" ",500)),COLUMN(A3)*500-499),500))
=TRIM(MID(SUBSTITUTE($A$3,",",REPT(" ",500)),SEARCH("=",SUBSTITUTE($A$3,",",REPT(" ",500)),COLUMN(A4)*500-499)+1,500))
 
Upvote 0
Instead of continually increasing the spaces and hoping it will be enough, this should work for any number of terms in the string (provided Excel has enough columns. ;)) I've tested to about 2,000 terms.

Excel Workbook
ABCDEFGHIJKLMNOPQRS
1ABCD-01=1,ABCD-02=1,ABCD-03=10,ABCD-04=10,ABCD-05=10,ABCD-06=10,ABCD-07=10,ABCD-08=10,ABCD-09=10,ABCD-10=10,ABCD-11=10,ABCD-12=10,ABCD-13=10,ABCD-14=10,ABCD-15=10,ABCD-16=10,ABCD-17=10ABCD-01ABCD-02ABCD-03ABCD-04ABCD-05ABCD-06ABCD-07ABCD-08ABCD-09ABCD-10ABCD-11ABCD-12ABCD-13ABCD-14ABCD-15ABCD-16ABCD-17
211101010101010101010101010101010
Extract Parts (2)
 
Last edited:
Upvote 0
Thank you both for all the help!

Both solutions work perfectly for my needs.

Thank you again! You just saved me hours of work.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top