User Agents

Excel Formula for Sheet Name: How to Get It

The formula to get the current worksheet's tab name in Excel is =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255). This returns the sheet name as text, and it updates automatically if you rename the tab. If you need the sheet name without the file path, this is the standard workaround because Excel has no built-in SHEETNAME function in older versions; Excel 365 and Excel 2021 offer =CELL("filename") combined with text functions, and newer dynamic array functions like =TEXTAFTER(CELL("filename"),"]") can simplify it further.

Why Excel Has No Direct Sheet Name Function

Excel's function library includes CELL, which can return information about a cell's formatting, location, or contents, but it does not include a dedicated function that returns the worksheet name. This omission is intentional: worksheet names are metadata, not cell data, and Microsoft has historically left metadata retrieval to the CELL function and VBA. The CELL function with the "filename" argument returns the full path, file name, and sheet name in a single string, such as C:\Reports\Budget.xlsx]Summary. The sheet name is everything after the closing bracket, which is why the formula uses FIND and MID to isolate it.

This behavior has been consistent across Excel versions for decades. In Excel 365, Microsoft added TEXTBEFORE, TEXTAFTER, and TEXTSPLIT, which make extracting the sheet name cleaner, but the underlying CELL function remains the only native way to get the tab name without using VBA or defined names.

How the Standard Formula Works Step by Step

The classic formula is built from three functions nested together. Understanding each piece helps you adapt it when your workbook path or sheet name contains unusual characters.

  1. =CELL("filename",A1) returns the full path, workbook name, and sheet name as text. The reference A1 can be any cell on the sheet; it only tells Excel which worksheet to report on.
  2. =FIND("]",CELL("filename",A1)) locates the position of the closing bracket that separates the workbook name from the sheet name.
  3. =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) extracts 255 characters starting immediately after the bracket, which captures the sheet name.

The number 255 is a safe upper limit because Excel sheet names cannot exceed 31 characters. You can replace 255 with 31 if you prefer, but 255 works universally and does not affect the result.

If the workbook has never been saved, CELL("filename") returns an empty string, and the formula returns an error or a blank. Save the file first, then the formula will work.

Simpler Alternatives in Excel 365 and Excel 2021

If you use a modern version of Excel, you can shorten the formula considerably with TEXTBEFORE and TEXTAFTER. These functions are available in Excel 365 and Excel 2021 but not in Excel 2019 or earlier.

  • =TEXTAFTER(CELL("filename",A1),"]") returns everything after the closing bracket, which is the sheet name.
  • =TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"]"),".xls") is not needed because the sheet name comes after the bracket and before any file extension; the extension appears before the bracket, not after.
  • =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))) is a more precise version of the classic formula that uses LEN instead of a fixed 255, though the result is identical for sheet names under 31 characters.

For users who prefer defined names, you can create a named formula called SheetName that refers to =MID(CELL("filename",!A1),FIND("]",CELL("filename",!A1))+1,255) and then use =SheetName anywhere in the workbook. This avoids repeating the long formula and makes it easier to read.

Common Problems and How to Fix Them

The CELL-based formula is reliable but has several known quirks that trip up even experienced users.

  • Unsaved workbook: CELL("filename") returns an empty string until the file is saved at least once. Save the workbook and recalculate.
  • Sheet name with special characters: If the sheet name contains a closing bracket, which is not allowed in Excel sheet names, the formula would break. Excel prohibits brackets in sheet names, so this is not a practical concern.
  • Volatile behavior: CELL is a volatile function, meaning it recalculates every time the workbook recalculates. In large workbooks with many CELL formulas, this can slow performance. Use it sparingly or convert the result to a static value if the sheet name does not change often.
  • External references: If you use CELL("filename") on a sheet that refers to an external workbook, the result may include the external workbook's path. The formula still extracts the sheet name correctly because it looks for the last closing bracket, but be aware of the context.
  • Protected view: In Protected View, CELL("filename") may return an empty string or an error. Enable editing to restore normal behavior.

Another common misconception is that the formula returns the sheet name of the cell referenced. In fact, CELL("filename",A1) returns the sheet name of the worksheet that contains the formula, not the sheet where A1 resides. If you need the name of a different sheet, you must place the formula on that sheet or use VBA.

Using VBA to Get Sheet Names

If you need more flexibility, such as getting the name of any sheet without placing a formula on it, VBA offers a direct solution. The immediate window or a custom function can return sheet names easily.

  • ActiveSheet.Name returns the name of the active sheet.
  • Worksheets("Sheet1").Name returns the name of a specific sheet.
  • ThisWorkbook.Worksheets(1).Name returns the name of the first sheet in the workbook.

You can create a user-defined function in a standard module:

Function SheetName() As String
    SheetName = Application.Caller.Worksheet.Name
End Function

Then use =SheetName() in any cell. This function is not volatile and works in all Excel versions that support macros. Note that workbooks with macros must be saved as .xlsm, and macros may be disabled by security settings.

Practical Examples and Use Cases

Knowing the sheet name is useful for building dynamic reports, creating navigation links, and labeling printed pages. For example, a dashboard sheet might use the formula to display "You are viewing: Summary" where Summary is the tab name. A table of contents can use hyperlinks that reference the sheet name, and a print header can include the sheet name using the formula in a cell that is then referenced in the header settings.

Another use case is conditional formatting or data validation that depends on the sheet name. For instance, you might want to highlight cells only on sheets whose names start with "Q" for quarterly data. The formula can be combined with LEFT or SEARCH to test the sheet name and drive formatting rules.

When sharing workbooks, be aware that the CELL formula returns the full path, which may expose folder names. If privacy is a concern, use VBA or strip the path manually. The CELL function does not provide an option to return only the sheet name without the path.

Frequently Asked Questions

Why does my formula return #VALUE!?

The #VALUE! error usually appears when the workbook has not been saved yet, so CELL("filename") returns an empty string and FIND cannot locate the bracket. Save the file and recalculate. It can also occur if the formula is entered in a sheet that is in Protected View.

Can I get the sheet name without the file path?

Yes. The standard MID/FIND formula extracts only the sheet name, which is the text after the closing bracket. The file path and workbook name are discarded. If you use TEXTAFTER, it also returns only the sheet name.

Does the formula update when I rename the tab?

Yes. CELL is a volatile function, so it recalculates when the workbook changes, including when you rename a sheet. The result updates automatically as long as calculation is set to automatic.

Is there a way to get the sheet name in Excel without VBA or CELL?

No native function returns the sheet name directly. You must use CELL, VBA, or a defined name that uses CELL. Some third-party add-ins offer a SHEETNAME function, but they are not part of Excel.

Why does the formula show the sheet name of a different sheet?

CELL("filename",A1) returns the sheet name of the worksheet containing the formula, not the sheet containing A1. If you reference a cell on another sheet, the formula still reports the current sheet. To get another sheet's name, place the formula on that sheet or use VBA.

Can I use this formula in Excel for the web?

Excel for the web supports CELL, but the "filename" argument may return different results or be unsupported in some contexts. In general, the formula works in Excel for the web when the file is saved to OneDrive or SharePoint, but behavior can vary. Test it in your environment.