Get the sheet name in excel

When working with Excel spreadsheets, sometimes you may have a need to get the name of the worksheet.

While you can always manually enter the sheet name, it won’t update in case the sheet name is changed.

So if you want to get the sheet name, so that it automatically updates when the name is changed, you can use a simple formula in Excel.

In this tutorial, I will show you how to get the sheet name in Excel using a simple formula.

Get Sheet Name Using the CELL Function

CELL function in Excel allows you to quickly get information about the cell in which the function is used.

This function also allows us to get the entire file name as a result of the formula.

Suppose I have an Excel workbook with the sheet name ‘Sales Data’

Below is the formula that I have used in any cells in the ‘Sales Data’ worksheet:

=CELL("filename"))
CELL formula to get workbook name and address

As you can see, it gave me the whole address of the file in which I am using this formula.

But I needed only the sheet name, not the whole file address,

Well, to get the sheet name only, we will have to use this formula along with some other text formulas, so that it can extract only the sheet name.

Below is the formula that will give you only the sheet name when you use it in any cell in that sheet:

=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))
formula to get the sheet name

The above formula will give us the sheet name in all scenarios. And the best part is that it would automatically update in case you change the sheet name or the file name.

Note that the CELL formula only works if you have saved the workbook. If you haven’t, then it would return a blank (as it has no idea what the workbook path is)

Wondering how this formula works? Let me explain!

The CELL formula gives us the whole workbook address along with the sheet name at the end.

One rule it would always follow is to have the sheet name after the square bracket (]).

Knowing this, we can find out the position of the square bracket, and then extract everything after it (which would be the sheet name)

And that’s exactly what this formula does.

The FIND part of the formula looks for ‘]’ and return it’s position (which is a number that denotes the number of characters after which the square bracket is found)

We use this position of the square bracket within the RIGHT formula to extract everything after that square bracket

One major issue with the CELL formula is that it’s dynamic. So if you use it in Sheet1 and then go to Sheet2, the formula in Sheet1 would update and show you the name as Sheet2 (despite the formula being on Sheet1). This happens as the CELL formula considers the cell in the active sheet and gives the name for that sheet, no matter where it is in the workbook. A workaround would be to hit the F9 key when you want to update the CELL formula in the active sheet. This will force a recalculation.

Alternative Formula to Get Sheet Name (MID formula)

There are many different ways to do the same thing in Excel. And in this case, there is another formula that works just as well.

Instead of the RIGHT function, it uses the MID function.

Below is the formula:

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

This formula works similarly to the RIGHT formula, where it first finds the position of the square bracket (using the FIND function).

It then uses the MID function to extract everything after the square bracket.

Fetching Sheet Name and Adding Text to it

If you’re building a dashboard, you may want to not just get the name of the worksheet, but also append a text before or after it.

For example, if you have a sheet name 2021, you may want to get the result as ‘Summary of 2021’ (and not just the sheet name).

This can easily be done by combining the formula we saw above with the text we want before it using the ampersand operator.

Below is the formula that will add the text ‘Summary of ‘ before the sheet name:

="Summary of "&RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))
Formula to append text before the sheet name in Excel

The ampersand operator (&) simply combines the text before the formula with the result of the formula. You can also use the CONCAT or CONCATENATE function instead of an ampersand.

Similarly, if you want to add any text after the formula, you can use the same ampersand logic (i.e., have the ampersand after the formula followed by the text that you want to append).

So these are two simple formulas that you can use to get the sheet name in Excel.

I hope you found this tutorial useful.

Other Excel tutorials you may also like:

  • How to Rename a Sheet in Excel (4 Easy Ways + Shortcut)
  • How to Insert New Worksheet in Excel (Easy Shortcuts)
  • How to Unhide Sheets in Excel (All In One Go)
  • How to Sort Worksheets in Excel using VBA (alphabetically)
  • Combine Data From Multiple Worksheets into a Single Worksheet in Excel
  • How to Compare Two Excel Sheets
  • How to Group Worksheets in Excel

In this example, the goal is to return the name of the current worksheet (i.e. tab) in the current workbook with a formula. This is a simple problem in the latest version of Excel, which provides the TEXTAFTER function. In older versions of Excel, you can use an alternative formula based on the MID and FIND functions. Both formula options rely on the CELL function to get a full path to the current workbook. Read below for a full explanation.

Workbook path

The first step in this problem is to get the workbook path, which includes the workbook and worksheet name. This can be done with the CELL function like this:

CELL("filename",A1)

With the info_type argument set to «filename», and reference set to cell A1 in the current worksheet, the result from CELL is a full path as a text string like this:

"C:pathtofolder[workbook.xlsx]sheetname"

Notice the sheet name begins after the closing square bracket («]»). The problem now becomes how to extract the sheet name from the path? The best way to do this depends on your Excel version. Use the TEXTAFTER function if available. Otherwise, use the MID and FIND functions as explained below.

TEXTAFTER function

In Excel 365, the easiest option is to use the TEXTAFTER function with the CELL function like this:

=TEXTAFTER(CELL("filename",A1),"]")

The CELL function returns the full path to the current workbook as explained above, and this text string is delivered to TEXTAFTER as the text argument. Delimiter is set to «]» in order to retrieve only text that occurs after the closing square bracket («]»). In the example shown, the final result is «September» the name of the current worksheet in the workbook shown. 

MID + FIND function

In older versions of Excel that do not offer the TEXTAFTER function, you can use the MID function with the FIND function to extract the sheet name:

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

The core of this formula is the MID function, which is used to extract text starting at a specific position in a text string. Working from the inside out, the first CELL function returns the full path to the current workbook to the MID function as the text argument:

CELL("filename",A1) // get full path

We then need to tell MID where to start extracting text. To do this, we use the FIND function with a second call to the CELL function to locate the «]» character. We want MID to start extracting text after the «]» character, so we use the FIND function to get the position, then add 1:

FIND("]",CELL("filename",A1))+1 // get start number

The result from the above snippet is returned to the MID function as start_num. For the num_chars argument, we hard-code the number 255*. The MID function doesn’t care if the number of characters requested is larger than the length of the remaining text, it simply extracts all remaining text. The final result is «September» the name of the current worksheet in the workbook shown.

*Note: In Excel user interface, you can’t name a worksheet longer than 31 characters, but the file format itself permits worksheet names up to 255 characters, so this ensures the entire name is retrieved.

To return the sheet name in a cell, use CELL, FIND and MID in Excel. There’s no built-in function in Excel that can get the sheet name.

1. The CELL function below returns the complete path, workbook name and current worksheet name.

Cell Function in Excel

Note: instead of using A1, you can refer to any cell on the first worksheet to get the name of this worksheet.

2. Use the FIND function to find the position of the right bracket. Add 1 to return the start position of the sheet name.

Find Function in Excel

3. To extract a substring, starting in the middle of a string, use the MID function. First argument (formula from step 1). Second argument (formula from step 2). Third argument (31).

Get Name of Current Worksheet

Explanation: the MID function shown above starts at position 24 and extracts 31 characters (maximum length of a worksheet name).

4. You may want to add text to the name of the sheet. Simply use the ampersand (&) operator as shown below.

Add Text to Sheet Name

5. To get the name of the second worksheet, simply refer to any cell on the second worksheet.

Get Name of Second Worksheet

Pro tip: use Excel VBA to display the sheet names of all Excel files in a directory. You can find detailed instructions here.

Содержание

  1. Get Sheet Name
  2. Insert Sheet Name In Cell: Easy! 3 Methods to Return the Worksheet Name
  3. Method 1: Insert the sheet name using built-in Excel functions
  4. How to Get the Current Sheet Name
  5. Example
  6. Generic Formula
  7. What It Does
  8. How It Works
  9. Excel Formula – Get Worksheet Name
  10. Get Worksheet Name – Excel Formula
  11. The CELL Function:
  12. The FIND Function:
  13. The MID Function
  14. Get Sheet Name in VBA
  15. Examples of using the SHEET and SHEETS functions in Excel formulas
  16. SHEET and SHEETS functions in Excel: description of arguments and syntax
  17. How to get sheet name by formula in Excel
  18. Examples of using the SHEET function and SHEETS
  19. Processing information about the sheets of the book on the formula Excel

Get Sheet Name

To return the sheet name in a cell, use CELL, FIND and MID in Excel. There’s no built-in function in Excel that can get the sheet name.

1. The CELL function below returns the complete path, workbook name and current worksheet name.

Note: instead of using A1, you can refer to any cell on the first worksheet to get the name of this worksheet.

2. Use the FIND function to find the position of the right bracket. Add 1 to return the start position of the sheet name.

3. To extract a substring, starting in the middle of a string, use the MID function. First argument (formula from step 1). Second argument (formula from step 2). Third argument (31).

Explanation: the MID function shown above starts at position 24 and extracts 31 characters (maximum length of a worksheet name).

4. You may want to add text to the name of the sheet. Simply use the ampersand (&) operator as shown below.

5. To get the name of the second worksheet, simply refer to any cell on the second worksheet.

Pro tip: use Excel VBA to display the sheet names of all Excel files in a directory. You can find detailed instructions here.

Источник

Insert Sheet Name In Cell: Easy! 3 Methods to Return the Worksheet Name

Often, you need to insert and work with the sheet name in an Excel sheet, for example if you are working with the ‘INDIRECT’-formula. Or, if you want to dynamically change headlines depending on the sheet name. If you don’t want to type the sheet name manually – which is very unstable – there are three ways to get a sheet name

Before we start: If you just have to insert the sheet name for a small amount of worksheets, please consider doing it manually. It usually is the fastest way.

Method 1: Insert the sheet name using built-in Excel functions

The easiest way is to copy the following function and paste it into your Excel cell:

This formula obtains the filename “=CELL(“filename”,A1)” and separates it after the character “]”. If you want to get the name of another Excel sheet, you have to change the cell reference from “A1” to any cell of the other worksheet. And depending on your version and language of Excel, you might have to translate the function names and maybe replace “,” by “;”.

Insert a sheet name with the cell function.

The big advantages of this method is that it doesn’t require any programming in VBA or a third-party Excel add-in.

On the downside, please note the following comments:

  • If you open a new file and paste this function, it won’t work before saving it.
  • The cell function is volatile. That means, it always calculates no matter if you’ve changed anything. This is a disadvantage for large Excel files where the performance of calculation is crucial.
  • Also, the cell function doesn’t translate to other languages. If your Excel is set to German, Spanish etc., you have to replace the “filename” part with the respective word in your language.

Do you want to boost your productivity in Excel?

Get the Professor Excel ribbon!

Add more than 120 great features to Excel!

Источник

How to Get the Current Sheet Name

Example

Generic Formula

filename – This is a system defined input for the CELL function.

What It Does

This formula will return the sheet name of the current sheet.

How It Works

CELL(“filename”) will return the full file path of the current workbook (let’s call this the FilePath) which includes the folder path, workbook name and the current sheet name. In our example FilePath is C:UsersJohn[How to Get the Current Sheet Name.xlsx]My Sheet.

FIND(“]”,FilePath) will return the location of the “]” character before the sheet name (let’s call this the Location). In our example FIND(“]”,FilePath) returns the value 132 since “]” is the 132nd character in the FilePath text string.

LEN(FilePath) will return the total character length of the FilePath text string (let’s call this the TotalLength). In our example LEN(FilePath) returns the value 140 since there are 140 characters in the text string.

We can now get the length of the sheet name by subtracting TotalLength-Location. In our example the sheet name length is 140-132=8 characters.

RIGHT(FilePath,TotalLength-Location) will then return the right most 8 characters of the FilePath, which gives us the sheet name. In our example this is My Sheet.

Источник

Excel Formula – Get Worksheet Name

Download the example workbook

Use this Excel formula to get the worksheet name

Get Worksheet Name – Excel Formula

To calculate the worksheet name in one Excel Formula, use the following formula:

Notice in the image above this formula returns sheet names GetWorksheetName and Sheet3.

This code may look intimidating at first, but it’s less confusing if you split it out into separate formulas:

Excel Functions – Worksheet Name

The CELL Function:

The Cell Function returns information about a cell. Use the criteria “filename” to return the file location, name, and current sheet.

The FIND Function:

The CELL Function returns [workbook.xlsx]sheet , but we only want the sheet name, so we need to extract it from the result. First though, we need to use the FIND Function to identify the location of the sheet name from the result.

The MID Function

Next, we will extract the desired text using the MID Function with the result of the FIND Function (+1) as the start_num.

Why did choose 999 for the num_characters input in the MID Function? 999 is a large number that will return all remaining characters. You could have chosen any other significantly large number instead.

Get Sheet Name in VBA

If you want to use VBA instead of an Excel Formula, you have many options. This is just one example:

Enter the current worksheet name in cell A1 using VBA.

Источник

Examples of using the SHEET and SHEETS functions in Excel formulas

SHEET function in Excel returns a numeric value corresponding to the sheet number referenced by the link passed to the function as a parameter.

SHEET and SHEETS functions in Excel: description of arguments and syntax

SHEETS function in Excel returns a numeric value that corresponds to the number of sheets referenced.

  1. Both functions are useful for use in documents containing a large number of sheets.
  2. A sheet in Excel is a table of all the cells that are displayed on the screen and are outside of it (a total of 1,048,576 rows and 16,384 columns). When sending a sheet to print, it can be divided into several pages. Therefore, the terms “sheet” and “page” should not be confused.
  3. The number of sheets in the book is limited only by the amount of PC RAM.

Function has only 1 argument in its syntax and is optional for: =SHEET( value ).

  • value is an optional function argument that contains text data with the name of the sheet or a link for which you want to set the sheet number. If this parameter is not specified, the function will return the number of the sheet in one of the cells of which it was written.
  1. When the sheet works, all sheets that are visible, hidden and very hidden are taken into account. Exceptions are dialogs, macros, and diagrams.
  2. If the function argument is a text value that does not match the name of any of the sheets contained in the book, the error #NA will be returned.
  3. If an invalid value was passed as an argument to the function, the result of its calculation will be the error #REF!.
  4. Within the object model (the hierarchy of objects in VBA, in which Application is the main object and Workbook, WorkSheet, etc., are child objects), the SHEET function is not available because it contains a similar function.

The function has the following syntax: =SHEETS( reference ).

  • reference — an object of reference type for which you want to determine the number of sheets. This argument is optional. If this parameter is not specified, the function will return the number of sheets contained in the book where it was written.
  1. This function counts the number of all hidden, very hidden and visible sheets, with the exception of charts, macros and dialogs.
  2. If an invalid reference was passed as a parameter, the result of the calculation is the error code #REF!.
  3. This function is not available in the object model due to the presence of a similar function there.

How to get sheet name by formula in Excel

Example 1. In carrying out the calculated work the student used the Excel program, in which he created a book of several sheets. For his own convenience, the student decided to display in the cells A2 and B2 of each sheet data on the name of the sheet and its serial number, respectively. For this, he used the following formulas:

Description of arguments for the MID function:

  1. =CELL(«filename») is a function that returns text in which the MID function searches for a specified number of characters. In this case, the value “C:UserssoulpDesktop[Workbook.xlsx] Static_Calculations” will return, where after the “]” symbol is the required text — the name.
  2. =FIND(«]»,CELL(«filename»))+1 is a function that returns the position number of the character «]», one is added so that the MID function does not take into account the character].
  3. 31 — the maximum number of characters in the name.

=SHEET() — this function without parameter returns the number of the current sheet. As a result of its calculation, we get the number of sheets in the current book.

Examples of using the SHEET function and SHEETS

Example 2. The Excel workbook contains several sheets. It is necessary:

  1. Return the current sheet number.
  2. Return the sheet number with the name «Static_calculations».
  3. Return the number of the sheet «Dynamic_calculations», if its cell A3 contains the value 0.

Enter the data in the table:

Next, we write the formulas for all 4 conditions:

  • For condition # 1, use the following formula: =SHEET()
  • For condition # 2, enter the formula: =SHEET(«Static_calculations»)
  • For condition number 3 we write the formula:

0″)’ >

The IF function checks whether the value stored in the A3 cell of the Dynamic_ calculations is equal to zero or null.

As a result, we get:

Processing information about the sheets of the book on the formula Excel

Example 3. To determine the contains several sheets. It is necessary to determine the total number of sheets, as well as the number contained between the “Static_calculations” and “Economic_calculations”.

The source table is:

The total number of sheets is calculated by the formula:

To determine the number contained between these two sheets, we write the formula:

  1. Static_calculations: Economic_calculations!A2 — A reference to cell A2 of the range of sheets between «Static_calculations» and «Economic_calculations» including these sheets.
  2. To get the desired value, 2 was subtracted.

As a result, we get the following:

The formula displays detailed information on the data on the sheets in a certain range of their location in the Excel workbook.

Источник

Return to Excel Formulas List

Download Example Workbook

Download the example workbook

This tutorial will demonstrate how to get a sheet name with a formula in Excel.

get sheet name Main Function

Get Sheet Name

In Excel there isn’t any one function to get the sheet name directly. But you can get a sheet name using VBA, or you can use the CELL, FIND, and MID functions:

=MID(CELL("filename"),FIND("]",CELL("filename"))+1,31)

Sample Sheet

Let’s go through the above formula.

CELL Function

We can use the CELL Function to return the file path, name, and sheet by inputting “filename”.

=CELL("filename")

CELL

To get the current worksheet’s name, you can use the function with or without the optional reference argument, referring to any cell on the current tab.

=CELL("filename",A1)

CELL A1

You can also get information about any other worksheet by referring to a cell on that sheet.

=CELL("filename",AnotherSheet!A1)

CELL A1 AnotherSheet

FIND Function

As shown above, the CELL Function returns the file path, name, and worksheet. We don’t need the path or workbook name, so we need to isolate the sheet name.

First use the FIND Function to determine the position of the character immediately before the sheet name (which is always “]”).

=FIND("]",B3)

FIND

MID Function

Since we have the last character position before the worksheet name, we can now use the MID Function to extract the characters after that position.  Our sheet name starts at the position found above + 1, but we don’t know how long the sheet name is. However, we do know the maximum length of a worksheet name (31), and we can use that in the MID Function:

=MID(B3,C3+1,31))

MID

Putting this all together yields our original formula:

=MID(CELL("filename"),FIND("]",CELL("filename"))+1,31)

Sample Sheet

Понравилась статья? Поделить с друзьями:
  • Get the last word meaning
  • Get the job done word
  • Get the hyperlink in excel
  • Get the date in excel
  • Get the address of a cell in excel vba