Get Folder Name

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,238
I know how to get the file path...

=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)

But is there a way to get just the FOLDER name (not the entire path) of the current file?

DJ
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,463
Try this...

=TRIM(MID(SUBSTITUTE(CELL("filename",A1),"",REPT(" ", 100)),(LEN(CELL("filename",A1))-LEN(SUBSTITUTE(CELL("filename",A1),"",""))-1)*100,100))
 
Upvote 0

AliGW

Banned
Joined
Mar 9, 2014
Messages
3,628
What exactly do you get as a result of this?


=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1)
 
Upvote 0

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,238
I get the path to the file

C:\Users\...\...\...\folder name I want\

Is there a way to capture the characters between the last two backslashes?

DJ
 
Upvote 0

AliGW

Banned
Joined
Mar 9, 2014
Messages
3,628
Is that the exact number of backslashes?
 
Upvote 0

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,238
No, and it can change if/when the file is moved or copied to another computer.

Can we count the backslashes from the right?
 
Upvote 0

AliGW

Banned
Joined
Mar 9, 2014
Messages
3,628
I was going to try and help, but I am getting the #VALUE! error with all of the formulae mentioned so far. Sorry!
 
Upvote 0

Forum statistics

Threads
1,191,684
Messages
5,987,994
Members
440,124
Latest member
dippy_egg

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
Top