19. Excel Tips - Function to return the worksheet name

There isn't a single function to return the sheet name, but you can use a combination of functions to get at it.
=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename"),1))
- Here's a breakdown of what it's doing:
Training Video on getting Worksheet Name:
| Attachment | Size |
|---|---|
| WorkSheet-Name-Workaround.xls | 32 KB |
»
- Nick's blog
- Add new comment
- 2908 reads

Function to return the sheet name: Tip #19
Hi!
Love your site!! However, I couldn't make this tip work properly. First, perhaps you'd like to tell your viewers that unless you save a workbook first, the CELL() function won't work.
OK, so I saved my workbook. Now, let's suppose I have 10 sheets in the workbook. Hooray, I can now put their names into the text area, too. I've named Sheet1 "NumeroUno," and I use your very clever formula to insert the sheet name into Cell D3. Great! Now D3 says NumeroUno. Onto Sheet2. I name that one "NumeroDos." I want its name to appear in K4. I use the formula and K4 reads NumeroDos. Proudly, I go back and check the NumeroUno sheet. Oops! Its D3 cell says NumeroDos.
And so on. All 10 sheets display -- in their cell references -- only the name of the last sheet, even though each sheet has a unique name. How come?? A more to-the-point question: How can this be fixed?
Thanks!
Marge
Worksheet name
good spot... I hadn't noticed this bug before.
I have attached a workaround workbook to the original posting (WorkSheet-Name-Workaround.xls).
Code:
Private Sub Worksheet_Activate()
Cells(2, 2).Calculate
End Sub
(assuming the formula is in B2)
Worksheet name
Nick, I have used the workaround you suggest to refresh the data containing the worksheet name on opening the worksheet. Brilliant, solves the problem!
Problem is I want to reference the worksheet names in a separate summary worksheet, and that doesn't work if my formula on that summary worksheet gets the value from the worksheet containing the worksheet name, because it's not been refreshed!
Any suggestions?
Thanks very much
Peter, UK
index page
to create an index page, why not use this:
excelexperts.com/VBA-Tips-Create-An-Index-Page
... or you could add code to the worksheet with the summary that on selection recalculates all the other sheet formulae...
Application.calculatefull
shld work