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)
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.