# A Formula To Return a Path, Filename and Sheet Name in Excel

## Handy Excel formulas to know

As you know, if you want the sheet name to appear on your printed report you can add it to the header or footer through **File**, **Page Setup** in Excel 2003 or **Page Layout**, **Page Setup** group in Excel 2007. It will print but it won't actually be in your worksheet.

If you want your spreadsheet's sheet name, filename or path to appear on your worksheet you can either type it into a cell or you can be smart and use the following formulas to dynamically show the info directly on your worksheet.

The following examples assume that the formulas are used in... **F:\Excel\[Formula Samples.xls]Sheet1**

Full path, file and sheet name: Formula: =CELL("filename",A1) Result: F:\Excel\[Formula Samples.xls]Sheet1

Filename only: Formula: =MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1, FIND("]",CELL("filename",A1))-FIND("[",CELL("filename",A1))-1) Result: Formula Samples.xls

Path only: Formula: =LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1),1)-1) Result: F:\Excel\

Sheet name only: Formula: =RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))- FIND("]",CELL("filename",A1),1)) Result: Sheet1

Rather than try to retype these formulas, you can select each of them above and copy them into your Formula Bar in Excel.

P.S. Note that these formulas won't work if your sheet is named Book1 or if your workbook is new and hasn't been saved. These formulas won't work in versions prior to Excel 2000.

**Website: **This is just one of hundreds of Microsoft Excel tips available at www.TheExcelAddict.com?link=hubpages that will save you a significant amount of time.

by Francis Hayes (The Excel Addict)

## Comments 9 comments

How do I pick what I need form this total name like

C:\Users\My name\Documents\A-91 files\2008 information\2009-04-27 files\details.xlsx finaldocument

From 8 part, how do I use only the last 4 or the last 5 etc..

Very nice. The formula for displaying the sheetname is exactly what I needed.

I'd like to understand the formula you've assembled but I get lost trying to decipher it with Excel's help.

Could you break this down for me?

Thanks in advance.

Very helpful. Your explanation answers the what, why and how questions that vex so many Excel users. Thank you and keep up the great work.

very helpful, francis, many thanks

In the Sheet name only: Formula: I have 4 words in the tab area Name Word1 Word2 Word3 how would I shorten the results to just the Name?

Thanks, Its very useful for me

hi there kevin sorry mate i`v took so long here is there contact

filling address , they have a wealth of knowledge , mention m wintekstold you to ring him

when i am using filename function in excel 1 (this is the filename) , and then i open excel 2, the cell in excel 1 changes from "excel 1" to "excel 2".

Please advise, how to prevent this.

## More time-saving tips available at...

- TheExcelAddict.com

Get FREE tips for Microsoft Excel at TheExcelAddict.com website - "101 Secrets of a Microsoft Excel Addict" ebook

• 101 Microsoft Excel Tips that you won't find on most other Excel websites. • 107 pages of easy-to-understand fully illustrated tips that will have you quickly promoted to the "Excel guru" at your office. - The Excel Addict Blog

Follow Francis Hayes' (The Excel Addict) blog as he shares with you many of the best tips, tricks and tutorials he has learned from working with Excel every day for over 16 years.

## More by this Author

- 7
This is one of those rare shortcuts in Excel that is so useful, it's amazing that it is never mentioned in basic training. As a matter of fact, I've rarely heard it mentioned anywhere. That's why few Excel users ever...

- 46
Learn how to sort dates in Microsoft Excel by month and day only, while ignoring the year.

9