ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Find Function (https://www.excelbanter.com/excel-worksheet-functions/25535-find-function.html)

Steve

Find Function
 
Hi
Cell A2=aaaa-bbb-cccc-d
in A1 I would like a formula to find the second "-" from the right and
return cccc-d. The number of characters in each segement of A2 can vary and
thennumber of segments may vary as well, so the search will have to be from
the right.
Thanks

Vasant Nanavati

Brute force :-):

=RIGHT(A2,LEN(A2)-FIND("/",SUBSTITUTE(A2,"-","/",LEN(A2)-LEN(SUBSTITUTE(A2,"
-",""))-1)))

--

Vasant

"Steve" wrote in message
...
Hi
Cell A2=aaaa-bbb-cccc-d
in A1 I would like a formula to find the second "-" from the right and
return cccc-d. The number of characters in each segement of A2 can vary

and
thennumber of segments may vary as well, so the search will have to be

from
the right.
Thanks




Harlan Grove

Vasant Nanavati wrote...
Brute force :-):

=3DRIGHT(A2,LEN(A2)-FIND("/",SUBSTITUTE(A2,"-","/",
LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))-1)))

..=2E.

You could save a function call and shorten this to

=3DMID(A2,FIND("=AC",SUBSTITUTE(A2,"-","=AC",
LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))-1))+1,256)

but that leaves the quibble that if the string could contain any
characters, the robust approach would be an array formula like

=3DMID(A2,LARGE(IF(MID(A2,ROW(INDIRECT("1:256")),1 )=3D"-",
ROW(INDIRECT("1:256"))),2)+1,256)



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

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