If you have a massive financial model that you duplicate every single month (e.g., “Q1_Financials”, “Q2_Financials”), you likely have a large title at the top of your dashboard that needs to reflect the current file name. Most people manually double-click the cell and retype the title every time they duplicate the sheet.
This manual data entry is prone to human error and wastes time. Instead of typing the title, you can use the highly obscure CELL function to interrogate the Google Sheets operating environment, grab the literal filename of the document you are currently working in, and dynamically display it directly on the canvas.
The Problem with Google Sheets
Unlike Microsoft Excel, which has a dedicated parameter to pull the filename, Google Sheets’ CELL function is heavily restricted. If you type =CELL("filename") in Google Sheets, it will crash. It simply does not support that parameter natively.
To bypass this limitation, we cannot use standard formulas. We must use a microscopic piece of Google Apps Script to build our own custom function that pulls the file name directly from the Google Drive API.
Step 1: Open the Apps Script Editor
- Open your Google Sheet.
- Click on Extensions in the top menu bar.
- Select Apps Script. A new browser tab will open, displaying a blank coding environment.
Step 2: Write the Custom Function
Delete any code currently in the window, and paste the following exact JavaScript code:
/**
* Returns the name of the current Google Sheets file.
*
* @return The name of the file.
* @customfunction
*/
function GETFILENAME() {
return SpreadsheetApp.getActiveSpreadsheet().getName();
}
- Click the Save project icon (the small floppy disk) at the top of the screen.
- You can now completely close the Apps Script browser tab and return to your Google Sheet.
Step 3: Deploy Your Custom Formula
Because of the @customfunction tag you included in the code, Google Sheets now permanently recognizes GETFILENAME() as a valid, native formula specifically for this document.
- Click on the cell where you want your dashboard title to appear (e.g., A1).
- Type the following formula:
=GETFILENAME() - Press Enter.
The Result
The cell will briefly say “Loading…” as it queries the Google Drive backend, and then it will instantly populate with the exact, literal name of the file (e.g., “Q1_Financials”).
If you click the title of the document at the very top of the web browser and rename the file to “Q2_Financials”, the cell on your canvas will automatically and instantly update to match it. You never have to manually type the title of your dashboard ever again.