The "script function not found" error in Google Sheets occurs because the Apps Script editor cannot locate a function name that matches exactly what is being called by a button, a custom menu, or a trigger. To fix this, you must ensure the function name in your script editor is spelled identically to the name assigned to the trigger or button, and that the project has been saved.
What You'll Need
- A Google account with access to the specific Google Sheet.
- The Google Sheet containing the script or the button causing the error.
- Access to the Apps Script editor (via the Extensions menu).
- The exact name of the function you intend to run.
Step-by-Step
- Open the Apps Script Editor: Open your Google Sheet. In the top menu, navigate to Extensions > Apps Script. This opens a new tab containing the JavaScript-based code associated with your spreadsheet. Note that menu labels may differ slightly depending on your account version or region.
- Verify the Function Name: Look through your code for the function declaration. It will start with the word
functionfollowed by a name, such asfunction myCustomTask() { ... }. Write down this name exactly as it appears, including the capitalization. JavaScript is case-sensitive;myCustomTaskis not the same asmycustomtask. - Check for Syntax Errors: Scan the code for missing curly braces
{}or missing parentheses. If the script has a syntax error, the entire file may fail to compile, meaning Google Sheets cannot "see" any of the functions inside it, even if the name is correct. Look for red underlines or red markers in the gutter of the editor. - Save the Project: Click the floppy disk icon (Save) in the toolbar or press Ctrl+S (Cmd+S on Mac). If the project is not saved, the Google Sheet is attempting to call a version of the script that does not yet contain your new function.
- Re-assign the Function to the Button: If you are using a drawing or image as a button, go back to your sheet. Right-click the button to reveal the three-dot menu in the top-right corner of the object. Select Assign script. In the text box, delete the existing text and carefully type the exact name of the function you verified in Step 2. Click OK.
- Verify Trigger Settings: If the error occurs during an automated event (like
onEditor a time-driven trigger), go to the Apps Script editor. On the left-hand sidebar, click the clock icon (Triggers). Find the trigger that is failing and click the pencil icon to edit it. Ensure the "Choose which function to run" dropdown is set to the correct function name. Save the trigger settings. - Refresh the Spreadsheet: Return to your Google Sheet and refresh the browser page. This forces the sheet to re-sync with the latest version of the saved Apps Script project.
Common Mistakes
One of the most frequent errors is a case-sensitivity mismatch. Many users name their function calculateTotal in the script editor but assign calculatetotal to the button. Because Google Apps Script is based on JavaScript, these are treated as two entirely different entities, resulting in the "not found" error.
Another common mistake is including the parentheses when assigning a script to a button. When you use the "Assign script" dialog in Google Sheets, you must enter only the function name (e.g., sendEmails), not the function call (e.g., sendEmails()). Adding the parentheses will cause the system to search for a function literally named "sendEmails()", which does not exist.
Users also frequently forget to save the script. It is possible to write a perfect function and assign it to a button, but if the save icon is still active (indicating unsaved changes), the Google Sheet is still looking at the previous version of the code where that function was missing.
Finally, placing functions inside other functions (nesting) can make them invisible to the global scope. If a function is defined inside another function, it cannot be called by a button or a trigger. Ensure your functions are defined at the top level of the script file.
Tips
To avoid naming conflicts and typos, use a consistent naming convention such as camelCase (e.g., processDataSheet). This makes it easier to distinguish between different functions and reduces the likelihood of spelling errors during assignment.
If you have a very large script project with multiple files (e.g., Code.gs, Utils.gs, Constants.gs), remember that all functions across all files in the same project share a global namespace. You do not need to specify which file the function is in; you only need the function name. However, ensure you haven't accidentally defined two different functions with the same name in different files, as this can cause unpredictable behavior.
Use the "Run" button inside the Apps Script editor to test your function before assigning it to a button. If the function runs successfully within the editor but fails in the sheet, the problem is almost certainly the assignment name or a permissions issue, rather than a problem with the code itself.
Troubleshooting
If you have verified the spelling and saved the project but the error persists, try these steps in order:
Check Permissions: Sometimes a script fails because it lacks the necessary authorization to run. In the Apps Script editor, select the function from the dropdown menu at the top and click "Run." If a prompt appears asking for permissions, follow the steps to authorize the script. Once authorized in the editor, try the button in the sheet again.
Check for Hidden Characters: If you copied and pasted the function name from a website or a document, there might be a hidden space or a non-printing character at the beginning or end of the name. Delete the name in the "Assign script" box and type it manually from scratch.
Inspect the Execution Log: In the Apps Script editor, click the "Executions" tab on the left sidebar. This shows a history of every time the script attempted to run. Look for the failed execution. If the error is "Function not found," it confirms a naming mismatch. If the error is different (e.g., "TypeError" or "ReferenceError"), the function was actually found, but it crashed during execution.
Create a New Test Function: To determine if the issue is with the specific function or the sheet's connection to the script, create a very simple test function: function testMe() { Browser.msgBox("It works!"); }. Save it and assign testMe to a button. If this works, your original function has a naming or structural issue. If this also fails, there may be a temporary glitch with the Google Apps Script engine for that specific document.
Frequently Asked Questions
Can I call a function from a different script project?
No, you cannot directly assign a function from a separate script project to a button in a sheet. The script must be "bound" to the spreadsheet or deployed as an add-on to be accessible via the "Assign script" feature.
Does the function need to be public?
In Apps Script, functions are generally accessible within the project. However, if you name a function with an underscore at the end (e.g., myPrivateFunction_()), it becomes private and cannot be called by buttons or triggers.
Why does it work for me but not for other users?
If the script is running as a custom function (used inside a cell like =MYFUNCTION()), it should work for everyone. However, if it is triggered by a button, the other user must have permission to run the script and may need to authorize it the first time they click the button.
Will renaming the function break my triggers?
Yes. If you change the name of a function in the code, any buttons or triggers assigned to the old name will immediately stop working and throw the "script function not found" error until you manually update the assignment name.
Does the script file name (e.g., Code.gs) matter?
The name of the file itself does not matter for calling functions. You only need the name of the function defined inside the file, regardless of which .gs file it resides in within that project.