Finding Text within a String (non-conforming)

CodyMonster

Board Regular
Joined
Sep 28, 2009
Messages
159
Everyone.. I have a string where I need to pull out a specific code/number, its begining three letters will not change, but its position and the length of the text might change.

Example:

<TABLE style="WIDTH: 291pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=388 x:str><COLGROUP><COL style="WIDTH: 291pt; mso-width-source: userset; mso-width-alt: 14189" width=388><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 291pt; HEIGHT: 12.75pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" id=td_post_2578426 height=17 width=388>DMRG-7983, XYZ CTP09/176, D3190, TORGOVY BRIDGE

I need to pull out the CTP09/176 the CTP prefix never changes but where its placed can be different, and the number of charters might change. I'm using the formula which works for 9 characters but not if its more or less

=TRIM(RIGHT(SUBSTITUTE(MID(M253,FIND("CTP",M253),9)," ",REPT(" ",255)),255))

In this case its CTP10/22

</TD></TR></TBODY></TABLE>
DMRG-7990, ABC Corp, CTP10/22, D4050, ATLANTIC

How do I get this to work so I pick up to the Right of CTP but left of the comma.

Thanks for you help!!!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try

=MID(A1,FIND("CTP",A1),FIND(",",SUBSTITUTE(A1,",","~",1))-FIND("CTP",A1))
 
Upvote 0
Try

=LEFT(MID(A1,FIND("CTP",A1),255),FIND(",",MID(A1,FIND("CTP",A1),255))-1)
 
Last edited:
Upvote 0
Thanks.. .that works if the string has the CTP after the first comma.. but it will and frequestly changes positions..

Your formula works for this..
91908-CPL, CTP09/174,D3873, CTC10/1,D143

But not for this..
91995-CPL CTP10/50, D143
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

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