Help removing characters in a cell

daydro

New Member
Joined
Oct 29, 2018
Messages
4
So here is my dilemma and it is driving me nuts.

Starting Cell possibilities:
"FM. Porter Jr. INACT "
"FM. Porter Jr. GTD "
"FM. Porter Jr. OUT "

Desired Output:
"M. Porter Jr."

There is a space before and after "INACT"/"GTD"/"OUT". Some have "Jr." or "III" or nothing after the name. My though was to remove all text after the 2nd space from the right but I can't figure out how to count the spaces from the right.

Current Formula:
=IFERROR((LEFT(MID(AI10, 2, LEN(AI10)),SEARCH(" ",MID(AI10, 2, LEN(AI10)),SEARCH(" ",MID(AI10, 2, LEN(AI10)))+1)-1)),"")

Works flawless on names without a suffix but if they have a suffix it cuts it off.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
=MID(SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),510)),""),2,255)


Excel 2010
AB
1FM. Porter Jr. INACTM. Porter Jr.
2FM. Porter GTDM. Porter
3FM. Porter Jr. OUTM. Porter Jr.
Sheet1
Cell Formulas
RangeFormula
B1=MID(SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),510)),""),2,255)
B2=MID(SUBSTITUTE(A2,TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",255)),510)),""),2,255)
B3=MID(SUBSTITUTE(A3,TRIM(RIGHT(SUBSTITUTE(A3," ",REPT(" ",255)),510)),""),2,255)
 
Upvote 0
Could you explain what this does?



=MID(SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),510)),""),2,255)


Excel 2010
AB
1FM. Porter Jr. INACTM. Porter Jr.
2FM. Porter GTDM. Porter
3FM. Porter Jr. OUTM. Porter Jr.
Sheet1
Cell Formulas
RangeFormula
B1=MID(SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),510)),""),2,255)
B2=MID(SUBSTITUTE(A2,TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",255)),510)),""),2,255)
B3=MID(SUBSTITUTE(A3,TRIM(RIGHT(SUBSTITUTE(A3," ",REPT(" ",255)),510)),""),2,255)
 
Upvote 0
Sure.
First it replaces all spaces with 255 spaces.
Then we take the right 510 characters (to get from the second space to the right from the original string - 255*2)
Since this of course has a lot of extra spaces in it, we TRIM it.
Now this will return the part we don't want of the string, so I substitute out of the original string.
Then return from the 2nd character to the end of the string.
 
Upvote 0
You are a genius! I can't tell you how long I struggled with this. Now I am using "Substitute" everywhere!
 
Upvote 0

Forum statistics

Threads
1,215,513
Messages
6,125,262
Members
449,219
Latest member
daynle

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