Help Deleting all text in cell following last \

maximillianrg

Board Regular
Joined
Aug 7, 2014
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
Hello Excel Masters

Using a command window in Windows 10 I have exported a directory structure to a text file and imported that text file it into excel so each line (over 9,000) contains the full path and full file name of the file. Some files are 4 folders deep and some are 10 folders deep.

C:\FOO\DOG\CAT\BEAR\LION\MEER CAT\GREAT PLAMES OF AFRICA\01021\THE GREAT PLANES.XLS
C:\GARBAGE\RED CANS\BLUE\0192121288452.DOC

I'm looking for a formula that I'm guessing will combine right and search that will locate the last "\" in the string and delete everything after it so the above examples would become the below

C:\FOO\DOG\CAT\BEAR\LION\MEER CAT\GREAT PLAMES OF AFRICA\01021
C:\GARBAGE\RED CANS\BLUE\

Thank you so much in advance for your help

Max
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Give this formula a try...
Excel Formula:
=LEFT(A1,FIND("|",SUBSTITUTE(A1,"\","|",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
 
Upvote 0
Solution
Give this formula a try...
Excel Formula:
=LEFT(A1,FIND("|",SUBSTITUTE(A1,"\","|",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
Hello Rick - Than worked like a champ - thank you so much - I always forget about the LEN Function - Nice work
 
Last edited by a moderator:
Upvote 0
No use for the OP with Excel 2016 but some of these text manipulation problems are getting much simpler with the latest available functions.

22 05 03.xlsm
AB
1C:\FOO\DOG\CAT\BEAR\LION\MEER CAT\GREAT PLAMES OF AFRICA\01021\THE GREAT PLANES.XLSC:\FOO\DOG\CAT\BEAR\LION\MEER CAT\GREAT PLAMES OF AFRICA\01021
2C:\GARBAGE\RED CANS\BLUE\0192121288452.DOCC:\GARBAGE\RED CANS\BLUE
TEXTBEFORE
Cell Formulas
RangeFormula
B1:B2B1=TEXTBEFORE(A1,"\",-1)
 
Upvote 0
@Peter,
That is probably Microsoft's ultimate strategy... improve the formula world so much that people and businesses almost have to upgrade to 365 just for the simplicity it will provide.
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,791
Members
449,188
Latest member
Hoffk036

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