Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Getting the Name of the Worksheet Into a Cell.

# Getting the Name of the Worksheet Into a Cell

by Allen Wyatt
(last updated August 29, 2020)

Kevin has a workbook containing 36 worksheets. He needs to have the worksheet name present in a cell of that worksheet. He has created a user-defined function that returns the worksheet name, but it returns the same name on all 36 worksheets—the name of whatever worksheet is displayed when the user-defined function is executed. He wonders if there is a macro, in user-defined function (UDF) form, that he can use that will always return the name of the sheet on which the function is used. In other words, in his 36-worksheet workbook, it should return 36 different results, depending on the worksheet in which it is used.

The short answer is yes, there is a way. In fact, there are a couple of ways. And, interestingly enough, you don't have to use a macro or function if you don't want to. For instance, here is a regular worksheet formula that will work in any cell on the worksheet:

```=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)
```

The instance of the CELL function in this formula returns the full name of the worksheet, including the filename and file path. The use of the FIND function results in the stripping out of everything except the worksheet name.

Note the use of a cell reference (A1) in each instance of the CELL function. This forces the CELL function to return the name of the worksheet that contains the cell reference. Without it, you will get the same result (the first worksheet) for each instance of the formula.

You should also know that the formula will not return valid results if you use it in a new workbook—one that hasn't been saved. You need to save the workbook so it actually has a name that can be returned by the CELL function successfully. It also will not work properly if the workbook or worksheet name contains a right bracket character ("]"). In that case, you'll want to use one of the other solutions discussed in this tip.

If you prefer to use a user-defined function, you can try something simple, like this function:

```Function TabName1() As String
Application.Volatile
TabName1 = ActiveSheet.Name
End Function
```

This function won't provide the desired outcome, however, because it always returns the name of the active worksheet. That means that if you have the function called on each of the sheets in your workbook, it will always return the name of the active sheet on each of those worksheets, instead of the name of the sheet on which the function is used. The following function provides better results:

```Function TabName2() As String
Application.Volatile
TabName2 = Application.Caller.Parent.Name
End Function
```

If you think you'll want to use the function to refer to a worksheet name elsewhere in the workbook, then this function will work better for you:

```Function TabName3(cell As Range)
TabName3 = cell.Worksheet.Name
End Function
```

This version of the function requires that you provide a cell reference—any cell reference—to a cell on the worksheet whose name you want to use.

Of course, if you would rather not use a user-defined function, you could simply create a macro that would stuff the name of each worksheet tab into the same cell in each worksheet. For instance, the following macro steps through each of the worksheets in the workbook and places the name of each worksheet into cell A1.

```Sub TabName4()
For J = 1 To ActiveWorkbook.Sheets.Count
Sheets(J).Cells(1, 1).Value = Sheets(J).Name
Next
End Sub
```

You should note that this approach is not dynamic (it needs to be rerun each time you change worksheet names or add new worksheets). It also overwrites anything that is in cell A1. (If you want the worksheet names placed in a different cell on each worksheet, change the values used in the Cells collection.)

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 (11419) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Getting the Name of the Worksheet Into a Cell.

##### 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

Inserting the Template Name in Your Document

Templates are a powerful part of the Word experience, as they allow you to create and format documents based on patterns. ...

Discover More

Copying a Cell without Formatting

When you are copying a cell from one place to another (perhaps even to a different worksheet), you may not want to copy ...

Discover More

Getting Rid of Hyperlinks in Footnotes

When you add hyperlinks to a document, Word makes them active, meaning you can click them to open the target of the ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

##### More ExcelTips (ribbon)

Determining a Worksheet's Number

When you add a new worksheet to a workbook, it receives a meaningful name such as "Sheet4" or "Sheet17." If you want to ...

Discover More

Copying a Single Cell to Multiple Worksheets

If you need to copy a cell from one worksheet to a bunch of other worksheets, the work can quickly get tedious. Make the ...

Discover More

Using Very Long Worksheet Tab Names

Excel places a limit on how many characters you can use in a worksheet name. This tip discusses that limit and provides ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

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}] 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 9 + 6?

2021-03-29 15:16:15

Notnice Nomore

So you (Microsoft) can give me (us) the number of the Sheet but not the name. And you think you deserve to be \$billionaires? If humans had any real brains left, you would be tarred and feathered for your pathetic APPs. It really is mind boggling.

btw (re: not a bot test) 6-3 used to be 3 but according to HARVARD now it may or may not be. So when I tell you that humans have lost their brains, beleive it.

2021-01-12 10:35:10

J. Woolley

According to Microsoft re. CELL("filename",...), "This value is not supported in Excel for the web, Excel Mobile, and Excel Starter."

2021-01-11 18:33:15

Ethan

Hello, I'm using the formula =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) and it works! Thank you. However, when I upload the excel spreadsheet to our office365 sharepoint site, and then open inside of a web browser, that field shows a "VALUE" error message.

Of course, I could always "open in excel" but I'm trying to create a simple shared document with others in my office and would like it to display the sheet name while being access inside of the web browser.

Any ideas?

Thanks!
Ethan

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.