How to get sheet name in ExcelWorking in different sheets within the same workbook is quite common in Excel. Often we rename these worksheets as per our requirements. But what if we want to fetch the name of a worksheet we are working on? Is it feasible? Indeed, it is! All you have to do is to refer to the sheet name, and cell address and excel will fetch the cell data of that respective sheet for you. Now the question arises of how to get the sheet name in Excel. Though there is no direct formula to get the sheet name, as we know, we can customise any formula. In this tutorial, we will discover the different methods to fetch the active worksheet name in Excel. Formula to fetch the active Worksheet NameThere are some essential day-to-day tasks in Excel for which Microsoft has not introduced any built-in function, and one such job is to get the sheet name. The first solution to this problem is to customise our own formula using multiple functions. To create a formula to fetch the worksheet name, we will merge three Excel functions, i.e., CELLS, FIND, and MID. =MID(CELL("filename"), FIND("]", CELL("filename"))+1,LEN(CELL("filename"))) You can enter the above formula in any Excel worksheet for which you want to fetch the sheet name. To understand the concept of the above formula below given is the step-by-step implementation of the formula that you can use in the worksheet to get the sheet name: Step 1: Specify CELL functionStart the formula with the '=' sign. Use the built-in CELL formula to return the complete path, workbook name and active worksheet name. This function will ask for two parameters. In the first parameter specify the info type that you want to return (in our case its "Filename"), and in the second parameter mention the cell address. Formula use: =CELL ("filename", A1) The above formula will return the following output. NOTE: Instead of the above cell reference A1, you can refer to different cell address as well within the first worksheet. It will also return the same worksheet name.Step 2: Merge above function with FINDAs you can see in the above result, the sheet name is after ']' bracket. Therefore, we will use the FIND function to look for the position of the right bracket.
Formula Used: = FIND("]",CELL("filename"))+1 Step 3: Extract a substring using MID functionThe last step is to worksheet name. To incorporate this, we will use the MID function, starting from the middle of the string.
Formula Used: =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,131) Explanation: The above formula will start extract a substring at position 104 and will fetch all the characters till position 131. The above formula will return the following output. Step 4. To fetch the name of another worksheetTo get the name of the second worksheet, simply refer to any cell on the second worksheet. Formula Used: =MID(CELL("filename",Sheet3!A1),FIND("]",CELL("filename",Sheet3!A1))+1,131) User Defined Formula using VBACreating a user-defined formula is the simplest thing to do in Excel. Many of you might find the above formula a bit complex, and sometimes, it might land up with errors or wrong output. So writing the formula is not the only option you have. You don't need to enter a complex formula but instead can do it with a simple user-defined code using Excel VBA. Now let's cover the various steps to create a user-defined formula and how we can implement this formula in our Excel worksheet to fetch the active worksheet's name in a cell. To understand the concept of the above formula below given is the step-by-step implementation of the formula that you can use in the worksheet to get the sheet name:
Code:
Formula Used: =mysheetname()
Within three lines of code, we covered the entire formula. Wasn't that much simpler and more accessible than the above mid formula? If you don't want to be involved in complex formulas, you can also use VBA to quickly solve any Excel problem; all you need is a little coding knowledge and a handful of practice. NOTE: You can use this function in any of the worksheet of the current workbook. This function is only customised for this workbook and is not applicable for other workbooks.That's it with the sheet names! Go and it both the methods a try. Use them anywhere as per your choice.
Next TopicRandomize a list in Excel
|