Formula to extract text from a string searching backwards

datadrvn

Board Regular
Joined
Apr 7, 2005
Messages
86
Been hunting for a few hours without success. I'm trying to extract a person's name from the middle of a cell. The names are in Last, First order but have text before / after within the cell.

Ex: 792-12345678-Test Project-Smith, David - technician

For the most part, the text in the cell isn't standardized so the text before / after the names varies both in length and characters, i.e., sometimes there are only two sections separated by hypens and other times they're separated by spaces. The only constants are that the there is always and only one comma in the string (between the Last and First names) and the character just before the last name is a hyphen (-). There are no middle initials of other name elements to consider.

I'm trying to extract just the name portion. I can use MID() to find the comma and go forward. However, I can't figure out how to start at the position of the comma and work backwards to find the 1st hyphen to the left of the comma, which would signify the beginning of the name information. Once I can get to the starting point, I believe I can get the rest.
 
been hunting for a few hours without success. I'm trying to extract a person's name from the middle of a cell. The names are in last, first order but have text before / after within the cell.

Ex: 792-12345678-test project-smith, david - technician

for the most part, the text in the cell isn't standardized so the text before / after the names varies both in length and characters, i.e., sometimes there are only two sections separated by hypens and other times they're separated by spaces. The only constants are that the there is always and only one comma in the string (between the last and first names) and the character just before the last name is a hyphen (-). There are no middle initials of other name elements to consider.

I'm trying to extract just the name portion. I can use mid() to find the comma and go forward. However, i can't figure out how to start at the position of the comma and work backwards to find the 1st hyphen to the left of the comma, which would signify the beginning of the name information. Once i can get to the starting point, i believe i can get the rest.


=left(mid(c21,find("-",c21,1+find("-",c21,find("-",c21)+1))+1,200),find("-",mid(c21,find("-",c21,1+find("-",c21,find("-",c21)+1))+1,200),1)-1)
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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