×

# 4 Formulas That Can Return An Excel Tab’s Name

By Chris Newman •  Updated: 09/04/23 •  8 min read

## Formula To Determine Current Sheet’s Name

In the vast world of Microsoft Excel, users often find themselves delving into intricate formulas and functions to extract specific pieces of information. One such task that might seem simple at first but can be a bit tricky is retrieving the name of the sheet where a formula resides.

While Excel doesn’t offer a direct function for this, with a combination of existing functions, this task can be achieved.

In this article, we’ll explore various formula-based methods to extract the sheet name, breaking down each formula step-by-step to ensure even the newest Excel users can grasp the concepts.

Here are the four formulaic routes you can take inside the Formula Bar to output the name of the tab that you are viewing (aka Active Sheet). I will explain how each Excel formula works in the following sections.

Excel Formula #1:

=TEXTAFTER(CELL(“filename”, A1), “]”)

Excel Formula #2:

=MID(CELL(“filename”, A1), SEARCH(“]”, CELL(“filename”, A1))+1, 300)

Excel Formula #3:

=REPLACE(CELL(“filename”, A1), 1, SEARCH(“]”, CELL(“filename”, A1)), “”)

Excel Formula #4:

=RIGHT(CELL(“filename”, A1), LEN(CELL(“filename”, A1))-SEARCH(“]”, CELL(“filename”, A1)))

## Formula #1: Combining TEXTAFTER and CELL Functions

### Excel Formula Solution:

=TEXTAFTER(CELL(“filename”, A1), “]”)

### Understanding the CELL Function

The CELL function provides information about the formatting, location, or contents of a cell based on the text command you provide to it.

=CELL(“filename”, A1) returns the full file path and sheet name of the workbook. For example, it might return something like C:\Users\JohnDoe\Documents\[Book1.xlsx]Sheet1.

### Understanding the TEXTAFTER function

The TEXTAFTER function was introduced into Microsoft Excel in 2022. This Excel function simply returns everything after a provided character or phrase.

For example, =TEXTAFTER(“I Love Excel So Much!”, “Excel”) would return ” So Much!“.

### Excel Formula Solution:

=MID(CELL(“filename”, A1), SEARCH(“]”, CELL(“filename”, A1))+1, 300)

### Understanding the CELL Function (Same as in Formula #1)

The CELL function provides information about the formatting, location, or contents of a cell based on the text command you provide to it.

=CELL(“filename”, A1) returns the full file path and sheet name of the workbook. For example, it might return something like C:\Users\JohnDoe\Documents\[Book1.xlsx]Sheet1.

### Understanding the SEARCH Function

The SEARCH function finds the position of a specified character or substring within a string.

SEARCH(“]”,CELL(“filename”,A1)) looks for the position of the right square bracket “]” in the full file path. In our example, it would return the position of “]” which is right before Sheet1. This results in an output of 39.

By combining the CELL and SEARCH functions, we’re essentially saying, “Find the position of the right square bracket in the full file path.”

### Understanding the MID Function

• The MID function extracts a substring from a string, starting at any position and for a specified number of characters.
• How we use it:
1. The first argument is the text string, which is our full file path from the CELL function.
2. The second argument is the starting position. We take the position of the right square bracket (from the SEARCH function) and add 1 to it. This ensures we start extracting right after the bracket.
3. The third argument is the number of characters to extract. We use 255 as a large number to ensure we capture the entire sheet name, no matter how long it is.

### Putting The Functions All Together

1. First, we get the full file path using CELL(“filename”,A1).
2. Then, we find the position of the right square bracket in this path using SEARCH(“]”,CELL(“filename”,A1)).
3. We add 1 to this position to start our extraction right after the bracket.
4. Finally, we use the MID function to extract the sheet name starting from this position and for a length of 300 characters (to ensure we capture the whole name – max is 255 characters, but 300 is easier to remember).

### Excel Formula Solution:

=REPLACE(CELL(“filename”, A1), 1, SEARCH(“]”, CELL(“filename”, A1)), “”)

### Understanding the CELL Function (Same as in Previous Formulas)

The CELL function provides information about the formatting, location, or contents of a cell based on the text command you provide to it.

=CELL(“filename”, A1) returns the full file path and sheet name of the workbook. For example, it might return something like C:\Users\JohnDoe\Documents\[Book1.xlsx]Sheet1.

### Understanding the SEARCH Function (Same as in Formula #2)

The SEARCH function finds the position of a specified character or substring within a string.

SEARCH(“]”,CELL(“filename”,A1)) looks for the position of the right square bracket “]” in the full file path. In our example, it would return the position of “]” which is right before Sheet1. This results in an output of 39.

By combining the CELL and SEARCH functions, we’re essentially saying, “Find the position of the right square bracket in the full file path.”

### Understanding the REPLACE Function

The REPLACE function replaces part of a text string with another text string.

How the REPLACE function works:

1. The first argument is the original text string, which is our full file path from the CELL function.
2. The second argument is the starting position of the text we want to replace. We start from the very beginning, so this is 1.
3. The third argument is the number of characters we want to replace. We use the position of the right square bracket (from the SEARCH function) as this tells us how many characters to replace up to and including the bracket.
4. The fourth argument is the text we want to replace with. In this case, it’s an empty string `""`, meaning we’re essentially removing the specified portion of the text.

### Putting The Functions All Together

1. First, we get the full file path using CELL(“filename”,A1).
2. Then, we find the position of the right square bracket in this path using SEARCH(“]”,CELL(“filename”,A1)).
3. We use the REPLACE function to replace everything from the beginning of the text up to and including the right square bracket with nothing (essentially removing it)

## Formula #4: Using the CELL Function with RIGHT and LEN

### Excel Formula Solution:

=RIGHT(CELL(“filename”, A1), LEN(CELL(“filename”, A1))-SEARCH(“]”, CELL(“filename”, A1)))

### Understanding the CELL Function (Same as in Previous Formulas)

The CELL function provides information about the formatting, location, or contents of a cell based on the text command you provide to it.

=CELL(“filename”, A1) returns the full file path and sheet name of the workbook. For example, it might return something like C:\Users\JohnDoe\Documents\[Book1.xlsx]Sheet1.

### Understanding the SEARCH Function (Same as in Previous Formulas)

The SEARCH function finds the position of a specified character or substring within a string.

SEARCH(“]”,CELL(“filename”,A1)) looks for the position of the right square bracket “]” in the full file path. In our example, it would return the position of “]” which is right before Sheet1. This results in an output of 39.

By combining the CELL and SEARCH functions, we’re essentially saying, “Find the position of the right square bracket in the full file path.”

### Understanding the LEN Function

The LEN function calculates the total number of characters in a text string.

LEN(CELL(“filename”,A1)) gives us the total length of the full file path. For our example, it would count all characters in C:\Users\JohnDoe\Documents\[Book1.xlsx]Sheet1. The resulting output in this example would be the value 45.

### Step 4: Understanding the RIGHT Function

The RIGHT function extracts a specified number of characters from the end (right side) of a text string.

How we are using the RIGHT function:

1. The first argument is the original text string, which is our full file path from the CELL function.
2. The second argument is the number of characters we want to extract from the end. This is determined by subtracting the position of the right square bracket (from the SEARCH function) from the total length of the full file path (from the LEN function).

### Putting The Functions All Together

1. First, we get the full file path using CELL(“filename”,A1).
2. We then determine the position of the right square bracket in this path using SEARCH(“]”,CELL(“filename”,A1)).
3. We calculate the total length of the full file path using LEN(CELL(“filename”,A1)).
4. We subtract the position of the right square bracket from the total length to determine how many characters are in the sheet name.
5. Finally, we use the RIGHT function to extract the sheet name based on the number of characters we determined in the previous step.

## I Hope This Microsoft Excel Article Helped!

In conclusion, while Excel might not have a direct function to fetch the sheet name, the versatility of its available functions allows us to craft our own solutions. By understanding and combining functions like CELL, SEARCH, MID, LEN, and RIGHT, we can manipulate text strings and extract the desired information. As with many tasks in Excel, there’s often more than one way to achieve the desired result. We hope this article has shed light on the logic behind these formulas, empowering you to not only use them but also to tweak and adapt them as needed. Remember, the key to mastering Excel lies in understanding the core principles behind each function and then creatively applying them to your unique challenges.

Hopefully, I was able to explain how you can write XML code to insert line breaks into your supertip text. If you have any questions about this technique or suggestions on how to improve it, please let me know in the comments section below.

### Keep Learning #### Chris Newman

Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.

[FREE Training] 10 Amazing Excel Efficiency Tricks. Why Don't People Know These?!

X