Содержание
- Naming
- Using the (Format > Sheet) sub menu
- Using the Worksheet Shortcut menu
- Using the Mouse
- Naming Conventions
- Important
- Get sheet name only
- Related functions
- Summary
- Generic formula
- Explanation
- Workbook path
- TEXTAFTER function
- MID + FIND function
- Sheet Name Code
- What is Sheet Name Code Excel Formula?
- Sheet name code Excel formula
- Sheet name code Excel template
- Download the Free Template
- Sheet Name Formula Template
- More Excel development
- How to Get the Sheet Name in Excel? Easy Formula
- Get Sheet Name Using the CELL Function
- Alternative Formula to Get Sheet Name (MID formula)
- Fetching Sheet Name and Adding Text to it
- What Excel formula returns the sheet name?
- 9 Answers 9
Naming
Excel names your worksheets based on the number of worksheets that have been created in that workbook.
You can easily change the name of your worksheets and this can be done in three ways:
1) Using the (Format > Sheet) sub menu.
2) Using the Worksheet Shortcut menu .
3) Using the Mouse to double click the worksheet name.
You can also use the (Format > Sheet) sub menu and select Rename.
Alternatively you can use the shortcut menu by right mouse clicking on the worksheet tab and selecting «Rename».
Using the Mouse
You can double click the sheet tab with the left mouse button.
To confirm your entry click on any cell or select another sheet.
You can keep the previous sheet name by pressing ESC before confirming.
Naming Conventions
Your worksheet names cannot have more than 31 characters and using the space is not recommended.
Giving your worksheets descriptive names will help you to remember where the data is stored.
They must obviously be unique within the workbook and cannot contain any of the following characters , / , * , ? , : , [ , ].
Important
Try to avoid really long descriptive names as these will be displayed on the tab at the bottom of your workbook.
Sheet names cannot be longer than 31 characters.
The default naming convention for worksheets is Sheet1, Sheet2, etc.
The worksheet name » History » cannot be used, in either upper or lower case. A worksheet with this name is used with the Track Changes feature so this name cannot be used to avoid any confusion. If you try and rename a sheet with this name you will get the message «History is a reserved name».
Источник
Get sheet name only
Summary
To get the name of the current worksheet (i.e. current tab) you can use a formula based on the CELL function together with the TEXTAFTER function. In the example shown, the formula in E5 is:
The result is «September» the name of the current worksheet in the workbook shown. In older versions of Excel which do not provide the TEXTAFTER function, you can use an alternate formula based on the MID and FIND function. Both approaches are explained below.
Generic formula
Explanation
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:
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:
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:
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:
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:
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:
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.
Источник
Sheet Name Code
This article outlines how to display the name of a sheet in Excel.
What is Sheet Name Code Excel Formula?
In Excel, if you want to display the name of a Sheet in a cell, you can use a combination of formulas to display it. Using the sheet name code Excel formula requires combining the MID, CELL, and FIND functions into one formula.
For example, if you are printing out a financial model onto paper or as a PDF, then you may want to display the sheet name on the top of each page. You can now easily do so by using this formula.
Sheet name code Excel formula
=MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,500)
(See screenshots below)
Example of creating the sheet name code Excel
Step 1: Type “CELL(“filename”,A1)”. The cell function is used to get the full filename and path. This function returns the filename of .xls workbook, including the sheet name. This is our starting point, and then we need to remove the file name part and leave only the sheet name.
Step 2: Type “FIND(“]”,CELL(“filename”)+1,500″. Essentially what the formula does is go into the file name and find the “]” which is where the workbook name ends. From there it moves over one character (+1) to where the sheet name starts. Finally, we add 500 to the end, or any number that is larger than the number of characters a sheet name would realistically have.
Congratulations, you have now displayed the name of a sheet in Excel!
Sheet name code Excel template
Download the Free Template
Enter your name and email in the form below and download the free template now!
Sheet Name Formula Template
Download the free Excel template now to advance your finance knowledge!
More Excel development
This has been CFI’s guide to the sheet name code Excel formula. To keep learning and expanding your skill set and knowledge base as a financial analyst, we highly recommend these additional resources to help you advance your career. Some of our most popular resources from CFI include:
Источник
How to Get the Sheet Name in Excel? Easy Formula
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.
This Tutorial Covers:
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:
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:
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:
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:
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:
Источник
What Excel formula returns the sheet name?
I have searched the excel function documentation and general MSDN search but have been unable to find a way to return the sheet name without VBA.
Is there a way to get the sheet name in an excel formula without needing to resort to VBA?
9 Answers 9
Not very good with excel, but I found these here
and A1 can be any non-error cell in the sheet.
For the full path and name of the sheet, use
Here’s a reasonably short one that has a couple added benefits:
Does a reverse lookup (most other answers go wrong direction) by using the often ignored REPT function.
A1 seems like a poor choice as there’s a considerably higher chance it errors compared to. $FZZ$999999 .
Don’t forget to absolute. Copying and pasting some of the other examples could error due to referential changes.
The ? is intentional as that shouldn’t be in the file path.
The below will isolate the sheet name:
For recent versions of Excel, the formula syntax is:
None of the formulas given in other answers supports the case if there is character ] in filepath.
The formula below is more complex, but it can handle such cases properly:
I had a module already open so I made a custom function:
Had a square bracket ‘]’ in the file name, so needed to modify the above formula as per the following to find the last occurrence of the square bracket. Verified that this works for 0,1 or more square brackets in the file name / path.
- Replaces all square brackets using the substitute function, then compares the length of the result with the length of the file name to identify the number of square brackets in the file name.
- Uses the number of occurrences of square brackets to substitute the last square bracket with 3 sequential square brackets ‘]]]’
- Uses the Find function to identify the location of the 3 square brackets in the string
- Subtracts the location of the 3 square brackets from the length of the full path
- Uses the result to get the right most characters (being the sheet name)
Previous comment above about saving the workbook first is also a key, as you’ll otherwise receive the #Value! result.
Источник
The term Worksheet used in Excel documents is a collection of cells organized in rows and columns. It is the working surface you interact with to enter data. Each worksheet contains 1048576 rows and 16384 columns and serves as a giant table that allows you to organize information.
Contents
- 1 How do you use worksheets in Excel?
- 2 What is the difference between worksheets and workbooks in Excel?
- 3 What is worksheet in MS Word?
- 4 How do I see the number of worksheets in Excel?
- 5 How do I find sheets in Excel?
- 6 Is worksheet and spreadsheet the same?
- 7 What is worksheet and workbook?
- 8 What is worksheet computer?
- 9 What is worksheet formatting?
- 10 How do you create a worksheet?
- 11 How many sheets are in a spreadsheet?
- 12 How many worksheets are there in a workbook by default?
- 13 How do I get a list of sheet names in Excel?
- 14 What is the difference between worksheet?
- 15 What are uses of spreadsheet?
- 16 What is the other name of a worksheet?
- 17 What is worksheet in accounting?
- 18 What is worksheet PDF?
- 19 What are the examples of worksheet?
- 20 How do you make worksheets fun?
How do you use worksheets in Excel?
This article describes the formula syntax and usage of the SHEETS function in Microsoft Excel.
Example.
Formula | Description | Result |
---|---|---|
=SHEETS() | Because there is no Reference argument specified, the total number of sheets in the workbook is returned (3). | 3 |
What is the difference between worksheets and workbooks in Excel?
Workbook is an excel file containing many worksheets. A worksheet has a single spreadsheet containing data.
What is worksheet in MS Word?
A worksheet is the name given to the large grid where you actually perform your calculations. A worksheet can be thought of as a single sheet of paper.Every worksheet has 16,384 columns (A – XFD) and 1,048,576 rows. This means that every worksheet contains 16,777,216 individual cells.
How do I see the number of worksheets in Excel?
Launch your workbook which you want to count the number of worksheets.
- Click Formula > Define Name, see screenshot:
- And in the New Name dialog box, specify a name in the Name text box, and then enter this formula =GET.WORKBOOK(1)&T(NOW()) to the Refers to text box, see screenshot:
How do I find sheets in Excel?
Just right-click on the little arrows in the bottom-left corner of your workbook. You’ll see a list of up to 15 worksheets in your workbook. If your workbook contains more that 15 sheets, click on More Sheets at the bottom of the list. This brings up a dialog that lists all sheets in your workbook.
Is worksheet and spreadsheet the same?
Fundamental Difference
The worksheet is single page spreadsheet or page in Excel, where you can write, edit and manipulate data, whereas the collection of such worksheets is referred as a workbook. It is very similar to a single page (worksheet) and a complete book (workbook).
What is worksheet and workbook?
A worksheet or sheet is a single page in a file created with an electronic spreadsheet program such as Microsoft Excel or Google Sheets. A workbook is the name given to an Excel file and contains one or more worksheets.
What is worksheet computer?
The term Worksheet used in Excel documents is a collection of cells organized in rows and columns. It is the working surface you interact with to enter data. Each worksheet contains 1048576 rows and 16384 columns and serves as a giant table that allows you to organize information.
What is worksheet formatting?
A cell style is a defined set of formatting characteristics, such as fonts and font sizes, number formats, cell borders, and cell shading. To prevent anyone from making changes to specific cells, you can also use a cell style that locks cells. Excel has several predefined cell styles that you can apply.
How do you create a worksheet?
Open a new, blank workbook
- Click the File tab.
- Click New.
- Under Available Templates, double-click Blank Workbook. Keyboard shortcut To quickly create a new, blank workbook, you can also press CTRL+N.
How many sheets are in a spreadsheet?
By default, there are three sheets in a new workbook in all versions of Excel, though users can create as many as their computer memory allows. These three worksheets are named Sheet1, Sheet2, and Sheet3.
How many worksheets are there in a workbook by default?
three sheets
Naming worksheets
When you open an Excel workbook, there are three sheets by default, and the default name on the tabs are Sheet1, Sheet2, and Sheet3. These are not very informative names.
How do I get a list of sheet names in Excel?
Enter SheetNames into the Name field, enter the following formula into the Refers to field: =REPLACE(GET. WORKBOOK(1),1,FIND(“]”,GET. WORKBOOK(1)),””), and then select OK. This action will create a named formula that can then be used in conjunction with the INDEX function to produce a list of worksheet names.
What is the difference between worksheet?
The Worksheet is a single-page spreadsheet. A workbook is just a file or a book. It consists of a matrix of rectangular cells, organized in a tabular form of rows and columns. The workbook consists of one or more worksheets, having various sorts of related information.
What are uses of spreadsheet?
The most common reason to use spreadsheets is to store and organize data, like revenue, payroll and accounting information. Spreadsheets allow the user to make calculations with this data and to produce graphs and charts.
What is the other name of a worksheet?
Worksheet Synonyms – WordHippo Thesaurus.
What is another word for worksheet?
job sheet | log |
---|---|
record | schedule |
What is worksheet in accounting?
An accounting worksheet is a document used within the accounting department to analyze and model account balances. A worksheet is useful for ensuring that accounting entries are derived correctly. It can also be helpful for tracking the changes to an account from one period to the next.
What is worksheet PDF?
worksheetspdf.com·@worksheetsPDF· WorksheetsPDF.com is a page where you can download files and educational resources to print PDF or DOC, you will find math, communication, 19,5mil seguidores.
What are the examples of worksheet?
Examples of spreadsheet programs
- Google Sheets – (online and free).
- iWork Numbers – Apple Office Suite.
- LibreOffice -> Calc (free).
- Lotus 1-2-3 (discontinued).
- Lotus Symphony – Spreadsheets.
- Microsoft Excel.
- OpenOffice -> Calc (free).
- VisiCalc (discontinued).
How do you make worksheets fun?
5 Easy Ways to Make Worksheets Engaging: Cut Them Up!
- Have a Snowball Fight! This is a fun and super easy way to get your students excited to practice those skills on a worksheet.
- Make a giant game board!
- Get them up and moving!
- Shoot some Hoops!
- Create your own Jeopardy Game.
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"))
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")))
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")))
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
I have searched the excel function documentation and general MSDN search but have been unable to find a way to return the sheet name without VBA.
Is there a way to get the sheet name in an excel formula without needing to resort to VBA?
pnuts
58k11 gold badges85 silver badges137 bronze badges
asked Feb 1, 2015 at 17:27
Not very good with excel, but I found these here
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)
and A1
can be any non-error cell in the sheet.
For the full path and name of the sheet, use
=CELL("filename",A1)
answered Feb 1, 2015 at 17:31
TravisTravis
1,2641 gold badge16 silver badges33 bronze badges
4
Here’s a reasonably short one that has a couple added benefits:
-
Does a reverse lookup (most other answers go wrong direction) by using the often ignored
REPT
function. -
A1
seems like a poor choice as there’s a considerably higher chance iterrors
compared to…$FZZ$999999
. -
Don’t forget to absolute. Copying and pasting some of the other examples could error due to referential changes.
-
The
?
is intentional as that shouldn’t be in the file path.=SUBSTITUTE(RIGHT(SUBSTITUTE(CELL("Filename",$FZZ$999999), "]",REPT("?", 999)), 999),"?","")
answered Jun 20, 2019 at 0:38
pgSystemTesterpgSystemTester
8,7802 gold badges22 silver badges49 bronze badges
The below will isolate the sheet name:
=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))
eli-k
10.7k11 gold badges43 silver badges44 bronze badges
answered Aug 8, 2016 at 3:52
2
For recent versions of Excel, the formula syntax is:
=MID(CELL("filename";A1);FIND("]";CELL("filename";A1))+1;255)
Wizhi
6,3684 gold badges24 silver badges47 bronze badges
answered Oct 17, 2018 at 10:59
OrbitOrbit
2121 silver badge7 bronze badges
None of the formulas given in other answers supports the case if there is character ] in filepath.
The formula below is more complex, but it can handle such cases properly:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1),FIND("?",SUBSTITUTE(CELL("filename",A1),"","?",LEN(CELL("filename",A1))-LEN(SUBSTITUTE(CELL("filename",A1),"","")))))+1,LEN(CELL("filename",A1)))
answered Apr 19, 2019 at 1:47
mielkmielk
3,88012 silver badges19 bronze badges
0
I had a module already open so I made a custom function:
Public Function Sheetname (ByRef acell as Range) as string
Sheetname = acell.Parent.Name
End Function
eli-k
10.7k11 gold badges43 silver badges44 bronze badges
answered Dec 21, 2017 at 15:00
3
Had a square bracket ‘]’ in the file name, so needed to modify the above formula as per the following to find the last occurrence of the square bracket.
Verified that this works for 0,1 or more square brackets in the file name / path.
=RIGHT(CELL("filename"),LEN(CELL("filename")) - FIND("]]]",SUBSTITUTE(CELL("filename"),"]","]]]",LEN(CELL("filename"))-LEN(SUBSTITUTE(CELL("filename"),"]","")))))
- Replaces all square brackets using the substitute function, then compares the length of the result with the length of the file name to identify the number of square brackets in the file name.
- Uses the number of occurrences of square brackets to substitute the last square bracket with 3 sequential square brackets ‘]]]’
- Uses the Find function to identify the location of the 3 square brackets in the string
- Subtracts the location of the 3 square brackets from the length of the full path
- Uses the result to get the right most characters (being the sheet name)
Previous comment above about saving the workbook first is also a key, as you’ll otherwise receive the #Value! result.
answered Jun 14, 2019 at 2:27
JokeyJokey
313 bronze badges
The below works for me and is simpler (to me at least) than other solutions, while still handling a square bracket in the file name:
=MID(CELL("filename", A1),6+SEARCH(".xlsx]",CELL("filename", A1)),32)
This assumes it is an «xlsx» file and that the filename will not contain «.xlsx]» in addition to the xlsx suffix, which in my case is an assumption that is safe enough to make.
If you wanted to handle both «.xlsx» and «.xls» file names, you could use:
=MID(SUBSTITUTE(CELL("filename", A1),".xls]",".xlsx]"),6+SEARCH(".xlsx]",SUBSTITUTE(CELL("filename", A1),".xls]",".xlsx]")),32)
answered Dec 26, 2020 at 21:19
mwagmwag
3,36929 silver badges36 bronze badges
I’m pretty sure you could have Googled this. I just did, and here is the very first thing that came up for me.
In Excel it is possible to use the CELL function/formula and the MID and FIND to return the name of an Excel Worksheet in a Workbook. The formula below shows us how;
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)
Where A1 is any non error cell on the Worksheet. If you want the full path of the Excel Workbook, simply use;
=CELL("filename",A1)
The only catch is that you have to save the file for this to work!
answered Feb 8, 2017 at 21:42
ASHASH
20.2k18 gold badges80 silver badges183 bronze badges
0
In this post, you’ll learn about with a detailed explanation of how to get sheet name in Microsoft Excel using VBA.
Table of Contents
- How to Get Sheet Name in Excel VBA?
- Get ActiveSheet Name
- Get Sheet Name by index Number
- Get Sheet Name by Code Name
- Check if Sheet Name Exists
Sheet names are stored in the Name property of the Sheets or Worksheets object. The Sheet Name is the “tab” name that’s visible at the bottom of Excel.
Get ActiveSheet Name
To display the ActiveSheet name in a message box, use the below code snippet
Get Sheet Name by index Number
To display the worksheet name in a message box by its index number:
To display the name of the last worksheet in the workbook:
MsgBox Sheets(Sheets.Count).Name
Get Sheet Name by Code Name
In the VBA Editor, there is an option to change the “code name” of a Sheet. The code name is not visible to the Excel user and can only be seen in the VBA Editor:
The VBA code name:
To get the Sheet name in a MsgBox using the VBA Code name:
Check if Sheet Name Exists
This is used to check whether the sheet name exists already.
Enter the following code in the module and click run
Code:
Function WorksheetExists2(WorksheetName As String, Optional wb As Workbook) As Boolean If wb Is Nothing Then Set wb = ThisWorkbook With wb On Error Resume Next WorksheetExists2 = (.Sheets(WorksheetName).Name = WorksheetName) On Error GoTo 0 End With End Function Sub FindSheet() If WorksheetExists2("Sheet1") Then MsgBox "Sheet1 is in this workbook" Else MsgBox "Oops: Sheet does not exist" End If End Sub