Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Finding the Parent Folder.

Finding the Parent Folder

by Allen Wyatt
(last updated September 10, 2016)

6

Lawrence asked if there was a way to devise a formula that would return the name of the parent folder for the current workbook file. He wanted this to return just the folder name, and he wanted it to be derived using a regular Excel formula, not a macro or user-defined function.

The answer is, yes, it is possible to figure out the parent folder using a formula, but the formula is rather long and complicated. There were several examples of formulas submitted by readers; the following formula is the most concise:

=MID(CELL("filename"), FIND(CHAR(1), SUBSTITUTE(CELL("filename"),
"\", CHAR(1), LEN(CELL("filename")) - LEN(SUBSTITUTE(CELL("filename"),
"\", "")) - 1)) + 1, FIND("[", CELL("filename")) - 2 - FIND(CHAR(1),
SUBSTITUTE(CELL("filename"), "\", CHAR(1), LEN(CELL("filename")) -
LEN(SUBSTITUTE(CELL("filename"), "\", "")) - 1)))

Please note that this is a real formula; it must appear on a single line in a cell.

The formula works by using the number of backslashes in the complete file path, and then replacing the second to the last slash with an ASCII value of 1. This value is then used as a "positioning aid" to help extract the parent folder's name.

Note, as well, that you may get a #VALUE error until you save the workbook in which the formula is contained. (Until that point, there is no path to analyze, so the various functions in the formula return a #VALUE error.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12084) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Finding the Parent Folder.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Sorting ZIP Codes

Sorting ZIP Codes can be painless, provided all the codes are formatted the same. Here's how to do the sorting if you ...

Discover More

Inserting the User's Name in a Cell

Need to understand who is using a particular workbook? There are a number of ways you can find out, as discussed in this tip.

Discover More

Headings On Your Printout

If you've got a table that spans multiple printed pages, you probably want to repeat a row or two of that table as a ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

CSV File Opens with Data in a Single Column

When you import a CSV file into an Excel worksheet, you may be surprised at how the program allocates the information ...

Discover More

Handling Leading Zeros in CSV Files

When dealing with files containing comma-separated values, you want to make sure that what gets imported into Excel ...

Discover More

Avoiding Scientific Notation on File Imports

When importing information from a CSV file, you may get unintended results from time to time. Here's how to force Excel ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 0?

2016-09-13 08:43:28

Doug Edwards

Okay - I just scrolled down to the comments submitted and found the answer to my question. Thank you!


2016-09-13 08:40:28

Doug Edwards

This is great! One step further - is there a formula for showing the full path? Sometimes I forget where I have placed a workbook. Thank you.


2016-09-12 09:25:49

Jomili

Couldn't we use instead
=TRIM(RIGHT(SUBSTITUTE(LEFT(CELL("filename"),FIND("[",CELL("filename"),1)-2),"",REPT(" ",100)),100))


2016-09-10 12:25:41

Rick

There is an advertisement covering up the right side of the formula!
ridiculous!


2016-09-10 10:40:21

Gyati Gupta

Its seems so complicated and scary but nevertheless thanks for sharing


2016-09-10 08:49:06

John Hooper

Excel 2016 has a simple formula for file name, path and worksheet: =CELL("filename")


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.