Method 1 – Using Excel Formula
- Excel lacks a built-in function to directly retrieve the sheet name, but we can create a formula using the MID, CELL, and FIND functions.
- Enter the below formula in any cell within your worksheet:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,31)
In this example, we named our worksheet Formula and then entered the formula in cell C5.
How Generic Formula Works
- The CELL function provides the full path, workbook name, and current sheet name.
=CELL("filename",A1)
- The FIND function locates the position of the right bracket (“]”) in the workbook name.
=FIND("]",CELL("filename",A1))+1
- The MID function extracts the sheet name.
- Arguments:
- 1st argument: =CELL(“filename”,A1) used in the first step.
- 2nd argument: =FIND(“]”,CELL(“filename”,A1))+1 used in the second step.
- 3rd argument: 31 which is the maximum length of a worksheet name in Excel.
Alternative Formula
Alternatively, you can use the below formula with the RIGHT function instead of the MID function:
=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1)))
Method 2 – Using VBA Code
2.1 Getting the Active Sheet Name
To get the active sheet name using VBA, use this simple code:
Sub SheetName()
Range("A1") = ActiveSheet.Name
End Sub
2.2 Finding the Sheet Name by Using Index Number
- To find a sheet name based on its index number (useful for multiple worksheets), use the below code.
- For example, we are in the second worksheet named vba1. With the following code, we can find the first sheet name which is Formula.
Sub Sheet Name()
Range("C5") = Sheets(1).Name
End Sub
With the following code, we can find out the last sheet name of a workbook. In this example, the last sheet name is vba2.
Sub SheetName()
Range("C6") = Sheets(Sheets.Count).Name
End Sub
Things to Remember
Remember, you can also use MsgBox to display VBA code results if you don’t need to store them in a cell.
Download Practice Workbook
You can download the practice workbook from here:
Related Articles
- How to Insert Excel Sheet Name from Cell Value
- How to List Sheet Name in Excel
- How to Rename Sheet in Excel
- How to Use Sheet Name Code in Excel
- How to Search by Sheet Name in Excel Workbook
<< Go Back to Excel Sheet Name | Excel Worksheets | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!