Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. 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 November 7, 2015)

30

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

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11419) applies to Microsoft Excel 2007, 2010, 2013, and 2016. 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

Can't Select Style Instances

Using the Styles and Formatting task pane, Word allows you to select all instances of a given style in your document. This ...

Discover More

Unwanted Graph Paper Effect

When you open a document or start to use Word, do you see a background that looks like graph paper? It could be because of ...

Discover More

Offering Options in a Macro

When creating macros, you often need to offer a series of choices to a user. This tip demonstrates how easy it is to offer ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Selecting All Visible Worksheets in a Macro

Do you need your macro to select all the visible worksheets (and just the visible ones)? It's not as easy as it sounds, but ...

Discover More

Creating a Worksheet Copy by Default

Excel makes it relatively easy to copy worksheets to a different workbook. That doesn't mean it couldn't be made simpler ...

Discover More

Moving from Sheet to Sheet

Need to move quickly through the worksheets in a workbook? Learn the keyboard shortcuts and you can make short work of this ...

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}] 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 two more than 4?

2017-08-31 12:54:10

Jon Young

Thank you!


2017-07-15 05:21:49

Michael (Micky) Avidan

@Paul Olmsted,
Assumming that cell G1 in TAb2 will hold the name for Tab1.
In sheets Tab2 Module type (copy from here) the following Event Macro.
*** Don't forgdet to enable Macros in Excel's options < Trust Center ***
-----------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$G$1" Then Exit Sub
Sheets(1).Name = [G1]
End Sub
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL


2017-07-15 03:31:30

Michael (Micky) Avidan

@Paul Olmsted,
Assumming that cell G1 in TAb2 will hold the name for Tab1.
In sheets Tab2 Module type (copy from here) the following Event Macro.
*** Don't forgdet to enable Macros in Excel's options < Trust Center ***
-----------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$G$1" Then Exit Sub
Sheets(1).Name = [G1]
End Sub
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” Excel MVP – Excel (2009-2018)
ISRAEL


2017-07-14 16:01:30

Paul Olmsted

I am trying to get a tab1 name to change to a cell in tab2. So that every time the cell is updated it will automatically update the name of tab1 to the cell value in tab2.

Alternately, I could have tab1 value update the data in the Cell in Tab2 whenever tab1 name is changed. Either formula would work for my needs.

Can you help? So far everything I have found is all when the cell is within the same tab.


2017-05-04 13:49:58

Anne Maloney

Ok. I solved it so I'll answer my own question - someone else may find it useful. I used the formula and multiplied by 1. Like this: =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)*1.


2017-05-04 13:42:19

Anne Maloney

Question: I've named all my worksheets in a particular file after the current date. Is there a way to tell excel to return the result as a number so that it can be formatted as a date (5/15/2017 for example)?


2017-02-01 07:50:21

Linda

Thanks - Most other sites miss the key bit of information re: A1.


2017-01-24 05:53:36

Michael (Micky) Avidan

@sarvesh,
Try:
=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-MAX(IF(NOT(ISERR(FIND("",CELL("filename",A1), ROW(1:255)))),FIND("",CELL("filename",A1),ROW(1:255)))))
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2017-01-24 01:52:26

Ehsan

Didn't work for me!


2017-01-23 15:06:37

Nihan

This article has saved my time today ! Thanks for sharing this useful information.


2017-01-19 00:41:56

sarvesh

how insert workbook name and sheet name as same with one formula


2017-01-17 12:12:21

IAN

I USE A WORKBOOK FOR WORK WITH MANY TABS NAMED DIFFERNT THINGS. I PRINT SOME OR ALL OF THESE TABS OFF TO ADOBE. IS THERE A WAY TO PREPOPULATE THE OPEN TABS NAME IN THE FILE NAME WHEN SAVING? I HAVE TO CHANGE IT EVERYTIME AS THE NAME OF THE WORKBOOK POPULATES HERE.


2017-01-12 13:49:40

Michael

Is there a way to modify this formula to get me the name of the worksheet from a cell with a link?
For example

Worksheet A will have a number from a cell in worksheet <Mike>
The cell will have ='<Mike>'!G11 I would like the formula to return <Mike>


2016-10-10 18:31:44

Michael (Micky) Avidan

@Lee,
Try:
=MID(CELL("filename",$A$1),FIND("]",CELL("filename",$A$1))+1,31)&" Amount"
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2016-10-09 08:27:09

Andy Lavery

Hey guys hope someone can solve my dilemma. Ok i have no problem with inserting the sheet name into a cell used both formula and VBA. My problem is whatever method i use it fails when opening excel in office 365 either by browser or by Ipad. Fully realize they are different/limited versions of excel just a hope that someone may have found a workaround.


2016-09-16 04:03:40

Jonathan Tuck

At some point the first method stopped working for me with some sheet names. For Example "Computing" gives #value! adding a space at the end of "Computing" resolves the problem. Any ideas why?


2016-09-08 11:48:32

Paul Burton

When I put =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) into an already saved work book all it stated in the cell was sheet 1


2016-09-07 11:24:37

Brian Canes

To take into account tabnames with excess blanks

=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(CELL("filename")," ",CHAR(232)),"]",REPT(CHAR(32),32)),32)),CHAR(232)," ")

Regards
Brian


2016-09-07 11:15:23

Brian Canes

=TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"]",REPT(CHAR(32),32)),32))

Regards
Brian


2016-09-06 13:28:24

Heike

This is wonderful. Thank you so much for a great and free answer. :)


2016-08-12 08:34:22

Lee

Is there away you can also add additional text to this. For example the tab is called "August", but I want the cell to say "August Amount"

Thanks


2016-07-10 06:06:52

Michael (Micky) Avidan

@Hemant Navgale,
Try the following Macro and change it to your needs:
---------------------
Sub Print_Range()
SN = [C4]
Sheets(SN).Activate ActiveSheet.Range("A1:B5").PrintOut
End Sub
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2016-07-10 05:48:22

Michael (Micky) Avidan

@Kathy,
Try: =TRIM(RIGHT(SUBSTITUTE(MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,31)," ",REPT(" ",255)),255))
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2016-07-09 08:00:52

Hemant Navgale

Sir,
Need your help.
I want a print micro.
look a value of cell C4 which will be sheet name, go to that sheet & print specific range of cells


2016-05-18 02:17:16

Emmanuel Cruz

Alternative (long version):

=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1)))


2016-05-10 12:12:36

Kathy

It works great! Can you get a portion of the sheet name in cell? A1 e.g. sheet name is Office Depot 68056 and I only want 68056 in the cell? This portion changes per worksheet.


2016-03-24 08:31:33

Fred Wander

Thank very much. I needed to place the sheet name in cell A1 in all the sheets of a spreadsheet with over 50 sheets. You are the only one who provided an easy solution without buying useless add-ins. Thank you so much! Fred wander


2016-02-06 04:19:34

manoj

Hi sir
I want one tip in excel
i want to create a covering letter so the sheet name in the entire workbook should come in a single sheet


2016-02-05 11:21:23

Christine

Thank you for this information. I just tried it and it worked. Do you have the formula for the next question: I have a row of dates Mon-Sun. Then a new worksheet for the next week. I have the first date a hard entry and the others a formula to add one each time. Is there a way to have the date formula be carried over to the next new worksheet without having the Monday be a hard entry? Thanks so much. Christine


2015-11-07 11:59:28

Steve Adams

Alternatives using the REPLACE function:

=REPLACE(CELL("filename",A1),1,FIND("]",CELL("filename",A1)),"")

or using the RIGHT function:

=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1)))


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.

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.