FIND text between backslashes in string

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
How do I get the text between the last two backslashes in a string?

For example, C:\Users\Folder 1\Folder 2\Folder 3\Folder 4\Folder 5\Folder 6\Folder 7\Folder 8\

I want "Folder 8"

Another example, C:\Users\Folder 1\Folder 2\Folder 3\Folder 4\

I want "Folder 4"

Any assistance will be greatly appreciated!

DJ
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Why have you started another thread?
Code:
=TRIM(LEFT(SUBSTITUTE(RIGHT(SUBSTITUTE(SUBSTITUTE( LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),"[",""),"\",REPT(" ",30)),60),REPT(" ",30),"\"),FIND("\",SUBSTITUTE(RIGHT(SUBSTITUTE(SUBSTITUTE( LEFT(CELL("filename",A1),FIND("]",CELL("filename",A1))-1),"[",""),"\",REPT(" ",30)),60),REPT(" ",30),"\"))-1))
 
Upvote 0
I did it when you were moving on and I thought it would be confusing to change my strategy/request for someone else 10 replies into the thread.

DJ
 
Upvote 0
One way...

=SUBSTITUTE(REPLACE(A2,1,FIND("#",SUBSTITUTE(A2,"","#",LEN(A2)-LEN(SUBSTITUTE(A2,"",""))-1)),""),"","")
 
Upvote 0
By "moving on", I am referring to when you said you were getting an error. I took that to mean you would not be able to help me. Then I started this thread. Then I suggested you save your file...

DJ
 
Upvote 0
How do I get the text between the last two backslashes in a string?

For example, C:\Users\Folder 1\Folder 2\Folder 3\Folder 4\Folder 5\Folder 6\Folder 7\Folder 8\

I want "Folder 8"
Give this formula a try...

Code:
=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",300)),600),300))
 
Last edited:
Upvote 0
djl0525

=MID(CELL("filename",A1);FIND("]",CELL("filename",A1))+1,31)


Would that be what you want?


Decio
 
Upvote 0
In A1 enter:

=CELL("filename",$A1)<strike></strike>

In B1 enter:

=LEFT(A1,FIND("\[",A1))<strike></strike>

Finally, in C1 enter in order to get the folder housing the file in A1:

=SUBSTITUTE(REPLACE(B1,1,FIND("#",SUBSTITUTE(B1,"","#",LEN(B1)-LEN(SUBSTITUTE(B1,"",""))-1)),""),"","")
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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