Extract Text before last slash

Zakkaroo

Active Member
Joined
Jul 6, 2009
Messages
383
I feel somewhat guilty for this, because there seems to be a fair bit of information out there on this topic, but I couldn't find the specific example I needed after much googling, I've struggled to adapt the example formulas I've seen (using TRIM, MID, LEFT, FIND, etc. and I'm under a bit of time pressure.

What I have is a long list of file locations and names

e.g.

c:\Test\Folders\My Stuff\wordDoc.docx
c:\My work\Safety Test.doc
c:\Trial\2015\June\Alpha\Manual Handling.docx

I need all the text before the last slash ... i.e. just the file location

So the results for the above, would be:

c:\Test\Folders\My Stuff
c:\My work
c:\Trial\2015\June

Any help would be appreciated.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
=LEFT(A1,FIND("@",SUBSTITUTE(A1,"\","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))/LEN("\")))-1)

NOTE: There's an error in your results, the last result should be

c:\Trial\2015\June\Alpha\

ie, the last slash is after Alpha not June
 
Upvote 0
Thanks so much, that appears to have worked - and yes, well spotted ... in my rush to post, I deleted too much of the text! :)
 
Upvote 0
Here is another formula, an array-entered** one, that will also work...

=LEFT(A1,MAX((MID(A1,ROW(1:300),1)="\")*(ROW(1:300)))-1)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0
=LEFT(A1,FIND("@",SUBSTITUTE(A1,"\","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))/LEN("\")))-1)

NOTE: There's an error in your results, the last result should be

c:\Trial\2015\June\Alpha\

ie, the last slash is after Alpha not June
=LEFT(A1,FIND("@",SUBSTITUTE(A1,"\","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))/LEN("\")))-1) - this formular on my side give an error of "Value" in excel can you kindly assist
 
Upvote 0
Hi,

I think you should start a new thread, with multiple samples of your text strings, and your expected results.
We'll be more than happy to help.
 
Upvote 0

Forum statistics

Threads
1,223,649
Messages
6,173,585
Members
452,522
Latest member
saeedfiroozei

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