Extract variable length string from variable data

toyz4me

New Member
Joined
May 27, 2015
Messages
3
Hi, Could you please help with a formula to extract "P4/*"up to the comma "," from the following examples:

Data --------------------------------------- Output
P4/3H6, ----------------------------------- P4/3H6
G6/3H4,GEN/18A12,P4/3H4, ------------ P4/3H4
P4/2C1.1,SLD/DIST, --------------------- P4/2C1.1
CEN/REVMET,P4/2C8, ------------------- P4/2C8
G8/3H3,L9/3H3,P4/3H3,R111/3H3, ---- P4/3H3
P4/3H15,S14/3H15, --------------------- P4/3H15

I have used MID and FIND in this formula: =MID(E4,FIND("P4/",E4)*1,8) to extract 8 characters, but the majority of the required strings are 6, some are 7 and a few are 8. My knowledge of Excel is not good enough to find the length of the P4/ string up to the comma and only extract it. I have searched and looked at some similar extraction formula but can not get them to work properly for me e.g. =MID(E4,FIND("P4/",E4)*1,(FIND(",",E4)-(FIND("P4/",E4)*1)))

Any help would be much appreciated
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Here is another formula you can consider...

=REPLACE(REPLACE(E4,FIND(",",E4,FIND("P4/",E4)),99,""),1,FIND("P4/",E4)-1,"")
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,916
Members
448,533
Latest member
thietbibeboiwasaco

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