Delimit by occurrence of special character

topher27

New Member
Joined
Apr 21, 2014
Messages
4
Hi,

I would like to be able to delimit or trim data by the number of occurrences of a special character. I want to be able to extract the file path but not the file names.
this is what I want it to do:

\home drive\Data\Web stuff\test.xls -> \home drive\Data\Web stuff
\home drive\Data\Web stuff\links\test.xls -> \home drive\Data\Web stuff\links
\home drive\Data\readme.txt -> \home drive\Data

I can use LEN to figure out how many "\" there are, but I'm not sure how to cut off the file name e.g.(test.xls) after the correct number of "\"s. Thanks for any help!

Chris

Excel 2010
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
since you know how many /'s, just use a simple LEFT function.

=LEFT(cell,numberofthelast/'s)
 
Upvote 0
Here is one way to do it...

=SUBSTITUTE(A1,"\"&TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",400)),400)),"")
 
Upvote 0
That worked great. Thank you very much!

The odds are the formula I gave you will work trouble-free for you; but, in thinking about it some more, it does have the potential to report back an incorrect value if the file name and extension were used in one of the earlier subdirectory names. For example.


\home drive\Data\test.xls stuff\links\test.xls

where the filename you want to remove (shown in green) is repeated in an earlier subdirectory name (shown in red). If you could have that situation, then you should not use the formula I posted earlier. The following formula will work correctly under all circumstances...


=LEFT(A17,LEN(A17)-LEN(TRIM(RIGHT(SUBSTITUTE(A17,"\",REPT(" ",400)),400)))-1)
 
Upvote 0
.. or insert ß (beta) to work with the formula in #3:

=SUBSTITUTE(A1&"ß",TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",999)),999))&"ß","")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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