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
[TABLE="width: 70"]
<tbody>[TR]
[TD][TABLE="width: 500"]
<tbody>[TR]
[TD]C:\Users\keames1\Desktop\2 - Current DD + N R9\[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
Many Thanks
[TABLE="width: 70"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,223,705
Messages
6,173,986
Members
452,541
Latest member
haasro02

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