• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Microsoft Excel Tips and Tricks - Computergaga

  • Home
  • Excel Online Courses
  • Excel Functions List
  • Free Downloads
  • Blog
  • Tutorials
  • About
Home / Formulas / Excel Formula to Display the Sheet Name in Cell

Excel Formula to Display the Sheet Name in Cell

This blog post looks at using an Excel formula to display the sheet name in cell. By finding the sheet name using an Excel formula, it ensures that if the sheet name is changed, the formula returns the new sheet tab name.

This tutorial covers two Excel formula examples. Firstly, using the CELL, MID and FIND functions. And then using the TEXTAFTER function with CELL.

Let’s begin by looking at the CELL function.

CELL Function in Excel

The CELL function is a fantastic, and relatively unknown, function in Excel. Its purpose is to return information about a cell such as its column, cell colour, its protected state, or filename.

It requires the information to return, entered as a string, and the reference to return the information from. A list is provided of the different types of information CELL can return.

List of info types that the CELL function can return

We need to use the function to return the filename from a given cell. Because our goal is to return the worksheet name, it does not matter what cell we use. Any cell on the sheet will work. In this example, cell A1 has been used (choosing any other cell would be weird, no?).

=CELL("filename",A1)

This function above will return the full filename of the cell such as;

C:\Users\Computergaga\Desktop\[return-sheet-name.xlsx]Chicago
Advanced Excel Formulas book

Returning Just the Sheet Name to a Cell

Now that we have the filename, we need to extract just the sheet name. The MID and FIND functions will be used for this.

The FIND function is used to return the position of the closing “]” + 1. The “]” indicates the end of the workbook reference, so the +1 returns the index for the first letter of the sheet name.

The MID function then extracts up to the next 32 characters. This is an excessive number but because sheet names cannot have more than 31 characters it ensures the full name is returned whatever it may be.

Here is the full Excel formula to display the sheet name in a cell;

=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,32)
Excel formula to extract sheet name using MID and FIND

Watch the Video

The CELL function is used twice in this Excel formula. This is fine, but to reduce calculation, the LET function could have been used to store the CELL formula result to be referenced later. This means it only calculates once, rather than twice.

=let(
filepath,CELL("filename",B2),
MID(filepath,FIND("]",filepath)+1,32)
)
Using LET to reduce calculations

Using the TEXTAFTER Function

In Excel 365, there are two new functions named TEXTBEFORE and TEXTAFTER. The TEXTAFTER function makes the process of returning a sheet name to cell even easier.

As its name suggests, the TEXTAFTER function returns all text after a given delimiter. It also has other cool features beyond the scope of this requirement.

In this formula the TEXTAFTER function uses the string returned by the CELL function and returns all text after the closing square bracket “]” delimiter. This time, the reference is omitted from the CELL function. When a reference is omitted, the cell that the formula belongs to is used.

=TEXTAFTER(CELL("filename"),"]")
Return sheet name in cell using the TEXTAFTER function

Related Posts:

  • Calculate age in Excel thumbnail
    How to Calculate Age in Excel
  • N Functions in Excel thumbnail
    N Function in Excel
  • Live currency exchange rate in Excel thumbnail
    LIVE Currency Exchange Rate in Excel
  • SWITCH function feature
    Excel SWITCH Function - Nested IF Function Alternative

Reader Interactions

Comments

  1. Neil Watkins says

    19 July 2016 at 10:29 pm

    Great function. I can get staff members to now remember where they put their files by this function. Thanks

    Reply
  2. Tom says

    6 August 2017 at 2:08 am

    Is there any way to reverse engineer this, so the sheet name is determined by a cell value?

    Reply
    • computergaga says

      6 August 2017 at 7:27 pm

      This can only be done with a macro using a statement such as Activesheet.Name = Range(“A1”).Value

      Reply
  3. Brian S Blackwell says

    26 January 2021 at 4:34 pm

    Sorry, but the filename (workbook name) is not the same as the sheet name inside a workbook.

    “A worksheet is a collection of cells where you keep and manipulate the data. Each Excel workbook can contain multiple worksheets.”

    Reply
    • Alan Murray says

      26 January 2021 at 4:42 pm

      I know, Brian. The formula returns the filename and extracts the sheet name from it.

      Reply
  4. Love Rai says

    20 July 2021 at 1:49 pm

    Note :- Formula Work only if your Sheet Name in Numeric
    =”=’E:\Contacts\”&”[“&SUM(MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,256))-1&”.csv”&”]”&SUM(MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,256))-1&”‘!$B$1048576″
    Use this Formula To Get Value from other Excel Sheet
    ________________

    Define Path = “=’E:\Contacts\”&”[”
    Give Sheet Name [if Sheet Name in Numericl] = SUM(MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,256))-1&”.csv”&”]”&SUM(MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,256))-1
    Cell No. = !$B$1048576

    Reply
  5. Johan Jordaan says

    24 July 2021 at 10:12 pm

    Is there a difference between Excel in Windows and Excel on Macbook?

    Reply
    • Alan Murray says

      26 July 2021 at 8:12 pm

      Yes, there are differences between the two. Not in formulas but in other areas especially VBA and Power Query.

      Reply
  6. Excel101 says

    24 September 2021 at 7:27 pm

    Hi! I’m just wondering what’s the meaning of the numbers +1 and 32?

    Reply
    • Alan Murray says

      10 November 2021 at 4:55 pm

      The + 1 is to start from the first character after the “]” and the 32 is a number to just ensure we return enough characters. 32 is more character than we require. We do not know how many characters in the sheet name, but we know 32 is more than enough.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Excel SWITCH Function – Nested IF Function Alternative
  • Sum Formulas Only in Excel
  • How to Calculate Age in Excel
  • Custom Sort in Excel
  • Case Sensitive Lookup with XLOOKUP in Excel
Advanced Excel Success book

Footer

Contact

[email protected]

LinkedIn Twitter YouTube

Useful Links

  • Home
  • Excel Online Courses
  • Tutorials
  • Sitemap
  • Privacy Policy
  • Jobs by Jooble

Course Topics

  • Blog
  • Charts
  • Courses
  • Dashboards
  • Downloads
  • Excel Tips
  • Formulas
  • Mail Merge
  • Office
  • PivotTables
  • Power BI
  • Power Pivot
  • Power Query
  • VBA

Join Our Mailing List

© Copyright 2009 Computergaga · All Rights Reserved ·