ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Truncating a text string (https://www.excelbanter.com/excel-worksheet-functions/61321-truncating-text-string.html)

bob

Truncating a text string
 
I would like to set up a formula that references a string in another cell but
truncates the beginning, middle, or end of it. The cell containing the data
always has five names separated by four commas, as shown below

Example:
A1 = Contains the text string "Simmons, Bogut, Magloire, Ford, Redd"
B1 = Want a formula that returns only the last two names in A1, "Ford, Redd"
C1 = Want a formula that returns only the first three names in A1, "Simmons,
Bogut, Magloire"
D1 = Want a formula that returns only the third name in A1, "Magloire"

Thank you for your help,
Bob

David Billigmeier

Truncating a text string
 
In B1: =RIGHT(A1,LEN(A1)-1-SEARCH(",",A1,1+SEARCH(",",A1,1+SEARCH(",",A1))))
In C1: =SUBSTITUTE(A1,", "&B1,"")
In D1: =RIGHT(C1,LEN(C1)-1-SEARCH(",",C1,1+SEARCH(",",C1)))


--
Regards,
Dave


"bob" wrote:

I would like to set up a formula that references a string in another cell but
truncates the beginning, middle, or end of it. The cell containing the data
always has five names separated by four commas, as shown below

Example:
A1 = Contains the text string "Simmons, Bogut, Magloire, Ford, Redd"
B1 = Want a formula that returns only the last two names in A1, "Ford, Redd"
C1 = Want a formula that returns only the first three names in A1, "Simmons,
Bogut, Magloire"
D1 = Want a formula that returns only the third name in A1, "Magloire"

Thank you for your help,
Bob


CLR

Truncating a text string
 
I think I would use the Data TextToColumns, comma delimited, to separate
all five names into their own columns, and then CONCATENATE the ones I wanted
back together............

Vaya con Dios,
Chuck, CABGx3



"bob" wrote:

I would like to set up a formula that references a string in another cell but
truncates the beginning, middle, or end of it. The cell containing the data
always has five names separated by four commas, as shown below

Example:
A1 = Contains the text string "Simmons, Bogut, Magloire, Ford, Redd"
B1 = Want a formula that returns only the last two names in A1, "Ford, Redd"
C1 = Want a formula that returns only the first three names in A1, "Simmons,
Bogut, Magloire"
D1 = Want a formula that returns only the third name in A1, "Magloire"

Thank you for your help,
Bob


Ron Rosenfeld

Truncating a text string
 
On Tue, 20 Dec 2005 11:31:04 -0800, bob wrote:

I would like to set up a formula that references a string in another cell but
truncates the beginning, middle, or end of it. The cell containing the data
always has five names separated by four commas, as shown below

Example:
A1 = Contains the text string "Simmons, Bogut, Magloire, Ford, Redd"
B1 = Want a formula that returns only the last two names in A1, "Ford, Redd"
C1 = Want a formula that returns only the first three names in A1, "Simmons,
Bogut, Magloire"
D1 = Want a formula that returns only the third name in A1, "Magloire"

Thank you for your help,
Bob


Two methods:

Using native Excel functions:

B1: =MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),3)) +2,255)
C1: =LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),3) )-1)
D1: =MID(C1,FIND(CHAR(1),SUBSTITUTE(C1,",",CHAR(1),2)) +2,255)

Using regular expressions:

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr/


B1: =REGEX.MID(A1,"\w+,\s\w+$")
C1: =REGEX.MID(A1,"\w+,\s\w+,\s\w+")
D1: =REGEX.MID(A1,"\w+",3)



--ron


All times are GMT +1. The time now is 09:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com