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

Distributing Columns Evenly

When you want the horizontal space in a table to be divided evenly among the columns in the table, you'll love this tip. How ...

Discover More

Quickly Displaying the Font Dialog Box

Want to quickly format some text in your document? Select, right-click, and make a selection, and you can get to the heart of ...

Discover More

Creating Venn Diagrams with Excel Data

A common way of representing data is to use a Venn diagram. Unfortunately, Excel doesn't have a precise way of creating Venn ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA 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 among ...

Discover More

Importing Multiple Files to a Single Workbook

If you use Excel to work with data exported from another program, you might be interested in a way to import a large number ...

Discover More

Full Path Names in Excel

Need to know what the full path name is for the current workbook? With a simple macro you can display the full path name in ...

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 four less than 9?

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.