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

Repaginating in a Macro

When creating a macro that extensively processes a document, you may need to periodically force Word to repaginate the ...

Discover More

Keyboard Shortcuts for Zooming

For whatever reason, Microsoft has never seen fit to provide built-in keyboard shortcuts zooming in and out. Here are some ...

Discover More

Compiling Misspelled Words from Documents

Word keeps track of the words that may be misspelled in a document. If you are working with a lot of documents, you may want ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Finding the Size of a Workbook

Keeping tabs on the size of a workbook can be important when using Excel. You have a couple of options that will allow you to ...

Discover More

How Excel Treats Disk Files

Workbooks are loaded from disk files, but workbooks aren't the only type of files that Excel can load. This tip provides a ...

Discover More

Saving a Workbook with a Preview

When you save your workbooks, Excel can also save a preview image (thumbnail) that can be displayed in the Open dialog box. ...

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 7 + 6?

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.