Friday, January 2, 2009

How to show the Sheet name in an Excel spreadsheet

There is a function in MS Excel called "cell" which gives you the filename of the current spreadsheet. For example, as shown above, =CELL("filename", A1) yields the following output:
D:\Documents and Settings\user\Desktop\[Demo Excel File.xls]This is sheet #1

But what if you want only the sheet name "This is sheet #1" without all the clumsy folder path in the front?

Here's the solution. By using a combination of the MID and FIND functions, you will be able to extract the sheet name and display it anywhere you like in the worksheet, as shown to the left:

This is the formula:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1, LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1)))


Basically, it strips out everything before the ] character, which contains the full path of the Excel file, leaving only the desired sheet name.

No comments: