Deleting characters after 3rd occurence of a string

M

Mark b.

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?
 
R

Ron Rosenfeld

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
 
B

Bob Phillips

=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))>2,LEFT(A1,FIND("/",A1,FIND("/",A1,FIND("/",A1)+1)+1)-1),A1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top