ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting characters after 3rd occurence of a string (https://www.excelbanter.com/excel-programming/416720-deleting-characters-after-3rd-occurence-string.html)

Mark B.

Deleting characters after 3rd occurence of a string
 
Trying to systematically delete all characters after the 3rd occurence of a
string and not having much luck with the Len, right and substitute commands.

In a region of cells, some of the data contains values separated by the '/'
character. when a cell contains the '/' character 3 (or more) times, I'd
like to remove that character and all characters to the right of it.

Thus:

apple/banana/cherry/date would get truncated down to apple/banana/cherry
animal/vegetable would remain animal/vefetable


thoughts?


--
Thanks,
Mark

Ron Rosenfeld

Deleting characters after 3rd occurence of a string
 
On Mon, 8 Sep 2008 14:18:00 -0700, Mark b.
wrote:

Trying to systematically delete all characters after the 3rd occurence of a
string and not having much luck with the Len, right and substitute commands.

In a region of cells, some of the data contains values separated by the '/'
character. when a cell contains the '/' character 3 (or more) times, I'd
like to remove that character and all characters to the right of it.

Thus:

apple/banana/cherry/date would get truncated down to apple/banana/cherry
animal/vegetable would remain animal/vefetable


thoughts?



=REPLACE(A1,FIND(CHAR(1),SUBSTITUTE(A1&CHAR(1),"/",CHAR(1),3)),255,"")

--ron

Bob Phillips[_3_]

Deleting characters after 3rd occurence of a string
 
=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))2,LEFT(A1,FIND("/",A1,FIND("/",A1,FIND("/",A1)+1)+1)-1),A1)

--
__________________________________
HTH

Bob

"Mark b." wrote in message
...
Trying to systematically delete all characters after the 3rd occurence of
a
string and not having much luck with the Len, right and substitute
commands.

In a region of cells, some of the data contains values separated by the
'/'
character. when a cell contains the '/' character 3 (or more) times, I'd
like to remove that character and all characters to the right of it.

Thus:

apple/banana/cherry/date would get truncated down to apple/banana/cherry
animal/vegetable would remain animal/vefetable


thoughts?


--
Thanks,
Mark




Mark B.

Deleting characters after 3rd occurence of a string
 
Thanks, Ron! Worked like a charm.
--
Thanks,
Mark


"Ron Rosenfeld" wrote:

On Mon, 8 Sep 2008 14:18:00 -0700, Mark b.
wrote:

Trying to systematically delete all characters after the 3rd occurence of a
string and not having much luck with the Len, right and substitute commands.

In a region of cells, some of the data contains values separated by the '/'
character. when a cell contains the '/' character 3 (or more) times, I'd
like to remove that character and all characters to the right of it.

Thus:

apple/banana/cherry/date would get truncated down to apple/banana/cherry
animal/vegetable would remain animal/vefetable


thoughts?



=REPLACE(A1,FIND(CHAR(1),SUBSTITUTE(A1&CHAR(1),"/",CHAR(1),3)),255,"")

--ron


Ron Rosenfeld

Deleting characters after 3rd occurence of a string
 
On Tue, 9 Sep 2008 07:07:01 -0700, Mark b.
wrote:

Thanks, Ron! Worked like a charm.
--
Thanks,
Mark


You're welcome. Glad to help. Thanks for the feedback.
--ron


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

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