Getting Path Information From A Text String

saltkev

Active Member
Joined
Oct 21, 2010
Messages
324
Office Version
  1. 2013
Platform
  1. Windows
Good Morning

I hope someone can help. I have a file path as shown below. I need to remove the file name from the end leaving just the path as shown in the second line. The path and file names will change.


C:\Users\keames1\Desktop\2 - Current DD + N R9\WCT Station 130 DDR9.xlsm
C:\Users\keames1\Desktop\2 - Current DD + N R9\

<tbody>
</tbody>

<tbody>
</tbody><colgroup><col></colgroup>
Many Thanks

<tbody>
</tbody><colgroup><col></colgroup>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, here is one option you can try:


Excel 2013/2016
AB
1C:\Users\keames1\Desktop\2 - Current DD + N R9\WCT Station 130 DDR9.xlsmC:\Users\keames1\Desktop\2 - Current DD + N R9\
Sheet1
Cell Formulas
RangeFormula
B1=TRIM(LEFT(SUBSTITUTE(A1,"",REPT(" ",255),LEN(A1)-LEN(SUBSTITUTE(A1,"",""))),255))&""
 
Upvote 0
Hi FormR, Why the &"" at the end?

Hi Pgc - there should be a backslash within the double quotes - the forum must have parsed it thinking it was HTML.

=TRIM(LEFT(SUBSTITUTE(A1,"\",REPT(" ",255),LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))),255))&"\"

Thanks for spotting.

EDIT: it got parsed in a few places - updates in red.
 
Last edited:
Upvote 0
You are right, I had not examined the formula just saw the &"" at the end.

But now I looked at the formula and you miss another \ in the Substitute. Must be the same problem as the other.

EDIT: I see that you already spotted it.
 
Last edited:
Upvote 0
Thanks For The Input Guys. However, I was looking for a VBA Solution, I already have a cell based solution.

Again Many Thanks

Kev
 
Upvote 0
I was looking for a VBA Solution

Hi, that's always worth mentioning at the outset.

One option, for example:

Code:
Dim S As String
S = "C:\Users\keames1\Desktop\2 - Current DD + N R9\WCT Station 130 DDR9.xlsm"
MsgBox Left(S, InStrRev(S, "\"))
 
Upvote 0

Forum statistics

Threads
1,216,033
Messages
6,128,427
Members
449,450
Latest member
gunars

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