Deriving the Worksheet Name

Written by Allen Wyatt (last updated June 12, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


There may be instances when you are developing a worksheet and you need to reference the name that you have assigned to the worksheet. (This is the name that appears on the worksheet tab, at the bottom of the Excel window.) Unfortunately, Excel does not include any intrinsic functions to do this. You can create such a function, however, by starting with the use of the CELL worksheet function.

If you include the following in a cell, Excel returns the fully path of the workbook, along with the sheet name:

=CELL("filename")

For instance, if you entered this into a cell in the Sheet3 worksheet of the MyBook workbook, the information returned by Excel might be something like C:\My Documents\[MyBook.xls]Sheet3 (depending, of course, on the drive and directory in which the workbook is saved).

To return just the worksheet name from this value, you could use the following in your cell:

=MID(CELL("filename"),(FIND("]",CELL("filename"))+1),50)

This will work for any worksheet name up to 50 characters in length. (If you routinely use different lengths, simply change the value in the expression.)

If you would prefer to use a macro-oriented approach, you can create a full-featured macro that will do the job. The following macro, SheetStuff, will return any of three separate items:

Function SheetStuff(numWanted As Byte) As String
    Select Case numWanted
        Case 1
            SheetStuff = ActiveSheet.Name
        Case 2
            SheetStuff = ThisWorkbook.Name
        Case 3
            SheetStuff = ThisWorkbook.FullName
        Case Else
            SheetStuff = ActiveSheet.Name
    End Select
End Function

To use this macro function, simply put =SheetStuff(X) in a cell in your worksheet. You should replace X with either 1, 2, or 3, depending on the information you want. If you use 1, the name of the current worksheet is returned. If you use 2, then the name of the workbook is returned. Finally, 3 returns the name and full path of the workbook.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2019) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Saving Changes when Closing

If you write a macro that makes changes to a document, you may want that macro to save those changes. There are several ...

Discover More

Changing Axis Tick Marks

Create a chart in Excel, and you may find that the tick marks shown on the axes in the chart aren't to your liking. It is ...

Discover More

Numbered Lists without Indentation

Do you want to modify how your numbered lists (or bulleted lists) are created? The key is to use styles to create your ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Reversing Names In Place

Do you want a way to reverse names within a cell, making them "last, first" instead of "first last?" Here's a handy macro ...

Discover More

Creating a Directory in a Macro

One of the things you can do with macros is to work with disk files. As you do so, you may have a need to create a new ...

Discover More

Generating Unique Numbers for Worksheets

You may need to automatically generate unique numbers when you create new worksheets in a workbook. Here's a couple of ...

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}] (all 7 characters, in the sequence shown) 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 six minus 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.