slicing between n and n+1th occurrence of String

alabatusa

New Member
Joined
Nov 8, 2009
Messages
9
Hi All,

Quick question:

I have the following data in excel cell:
"alpha.beta.charlie.delta.epsilon.foxtrot.gamma"

I wish to retrieve the value between the last and second last dot("."). That in this case is Foxtrot

I have done several methods to do this, such as using a nested find function in this case to find the the position of the 5th dot and and 6th dot. Once i have the positions of each simply use a mid function between these 2 locations to find "Foxtrot"

The problem with this however is that the number of dots in a text will change, and i always wish to pick up the value between the last and second last dot.

e.g in another case if i have "av.ac.ad.o"
i would want to return "ad"

Is there any easy way to do this, without using vba or plugins

Thanks
Atif
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this
Excel Workbook
AB
1alpha.beta.charlie.delta.epsilon.foxtrot.gammafoxtrot
Sheet1
Excel 2003
Cell Formulas
RangeFormula
B1=TRIM(LEFT(SUBSTITUTE(MID(A1,SEARCH("~~",SUBSTITUTE(A1,".","~",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))-1))+1,255),".",REPT(" ",255)),255))


There might be a much simple solution than this, but my mind is not working :(
 
Upvote 0
Thanks, i will try that


If A1 = “alpha.beta.charlie.delta.epsilon.foxtrot.gamma”
Let A2 = LEN(A1)-LEN(SUBSTITUTE(A1,".",""))
= Number of “.” in data
To then return data between 2nd last and last “.”, can be generated in A3.
Where A3 =IFERROR(MID(A1,FIND(CHAR(5),SUBSTITUTE(A1,".",CHAR(5),A2-1))+1,FIND(CHAR(5),SUBSTITUTE(A1,".",CHAR(5),A2))-FIND(CHAR(5),SUBSTITUTE(A1,".",CHAR(5),A2-1))-1),A1)
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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