In Excel: use =TEXTAFTER(CELL("filename", A1), "]") on Microsoft 365, or =MID(CELL("filename",A1), FIND("]", CELL("filename",A1))+1, 255) in any version — and save the file first, because CELL("filename") returns an empty string until it has been saved.
Save the workbook — CELL("filename") returns an empty string until the file exists on disk.
On Microsoft 365: =TEXTAFTER(CELL("filename", A1), "]").
On older versions: =MID(CELL("filename",A1), FIND("]", CELL("filename",A1))+1, 255).
Always pass the second argument (A1). Without it the result follows the last-calculated sheet, not this one.
For the file name instead: =TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]").
Wrap it in IFERROR if the workbook may be used before its first save.
What this does
Excel has no SHEETNAME function. The only route is CELL("filename", A1), which returns the full path in the form C:\Reports\[Budget.xlsx]January — path, file name in square brackets, then the sheet name. Everything after the closing bracket is the sheet name, so the formula is one text extraction. Three details decide whether it works. The second argument matters: CELL("filename") with no reference returns the name of whichever sheet was last calculated, which on a multi-sheet workbook gives the wrong answer at unpredictable times — always pass a cell on the sheet you mean, such as A1. The workbook must have been saved at least once, or the function returns "". And CELL is volatile, so it recalculates on every change in the workbook; on a sheet with hundreds of these it is worth noticing. To get the file name instead, take the text between the brackets; to list every sheet name, Power Query or a small macro is the practical route. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. Treat “sheet name code excel” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected sheet shows up while it is still harmless. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That turns a text operation that turns messy entries into clean, usable data into a method you can reuse, explain, and defend when the workbook leaves your screen.
A worked example
On a sheet named January in Budget.xlsx: =CELL("filename", A1) returns C:\Reports\[Budget.xlsx]January. =TEXTAFTER(CELL("filename", A1), "]") returns January. Rename the tab to Jan-2026 and the cell updates by itself, which is why a report header built this way can never disagree with the tab it sits on. A report header that reads its own tab name cannot go stale, which is exactly what a typed one does the first time someone renames the sheet. If there is any chance you will reuse this, drop it into a small template tab right now: a labelled input area on the left and the formula beside it, checked once against the tool above. Next time the same question comes up, the answer is a single paste away instead of a rebuild from memory.
In Google Sheets
Google Sheets handles this almost identically to Excel. The formula syntax above is the same, and the menu lives under a slightly different label rather than a ribbon tab. Use the platform toggle at the top of the page to switch every keyboard shortcut between Windows and Mac, and expect at most cosmetic differences in naming. Nothing on this page is behind a login: the tool runs entirely in your browser, the formula is shown in full with one-click copy, and the steps work the same on Windows and Mac. That is the whole promise here — the exact answer, a way to prove it on your own numbers, and just enough context to make it stick. Here is the takeaway for “sheet name code excel”: copy the answer if you are busy, but if you have a spare few minutes, rebuild the example in Excel yourself with the tool above open beside it. That single pass — type it, run it, watch the result move when you change an input — is what turns a formula you found into a technique you trust. Keep your inputs labelled and referenced, never hard-coded, and the same sheet stays correct and auditable as it grows. Done that way, you will not need to look this up again, and you will be the person others ask.
Common mistakes
- Omitting the cell reference, which produces a name that changes as other sheets recalculate.
- Testing in an unsaved workbook and concluding the formula is wrong when it is returning "" correctly.
- Expecting a SHEETNAME function to exist — SHEET() returns the index number, not the name.
- Putting hundreds of CELL calls on one sheet and adding a volatile recalculation to every keystroke.
- Hard-coding the sheet name into a title instead, which then silently disagrees with the tab after a rename.
Frequently asked questions
How do I get the sheet name in a formula?
=TEXTAFTER(CELL("filename", A1), "]") on Microsoft 365, or the MID/FIND version in older releases. The workbook must have been saved.
Why does my sheet-name formula return nothing?
The workbook has never been saved, so CELL("filename") has no path to report. Save it once and the formula fills in.
Why does the wrong sheet name appear?
The formula omits the second argument. CELL("filename") alone reports the last-calculated sheet; CELL("filename", A1) reports this one.
How do I get the file name instead of the sheet name?
Take the text between the square brackets: =TEXTBEFORE(TEXTAFTER(CELL("filename",A1),"["),"]").