Sunday, October 10, 2010

Filename formula

There may be times when you need to insert the name of the current workbook
or worksheet in to a cell.

This can be done by using the CELL() function, shown below.
C:\DOCUME~1\SALEHK~1\LOCALS~1\Temp\Temporary Directory 2 for Excel function TUTOR.zip\[Excel function TUTOR.XLS] Filename formula
=CELL("filename")

The problem with this is that it gives the complete path including drive letter and folders.
To just pick out the workbook or worksheet name you need to use text functions.

To pick the Path.
C:\DOCUME~1\SALEHK~1\LOCALS~1\Temp\Temporary Directory 2 for Excel function TUTOR.zip\
=MID(CELL("filename"),1,FIND("[",CELL("filename"))-1)

To pick the Workbook name.
Excel function TUTOR.XLS
=MID(CELL("filename"),FIND("[",CELL("filename"))+1,FIND("]",CELL("filename"))-FIND("[",CELL("filename"))-1)

To pick the Worksheet name.
Filename formula
=MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)

No comments:

Post a Comment

Popular Posts