Open your spreadsheet in Google Sheets on a computer, choose Data > Named functions, click Add new function, then fill in a name, the argument placeholders and the formula, and finish with Next and Create. From then on you type it like a built-in function, for example =MARGIN(B2,C2). These steps are for Sheets in a web browser, and the feature is available with personal Google Accounts and Google Workspace accounts.
What a named function is made of
A named function is a formula you’ve saved under your own name so you can reuse it without retyping the logic. Google’s help page lists four main parts:
- Function name: what you type after the equals sign. Sheets shows it in capitals.
- Function description: a sentence that appears in the “About” section of the formula help box.
- Argument placeholders (optional): words that stand in for the cells or values someone will supply later, such as price or cost. Think of them as labeled blanks.
- Formula definition: the formula itself, written with the placeholders where cell references would normally go.
On a second screen you can add an argument description and an argument example for each placeholder. Together with the description, these fill the help box people see when they start typing your function, so a coworker can use it without asking you what goes where.
Rules for names and placeholders
Sheets rejects a function name that:
- matches a built-in function such as SUM, or is TRUE or FALSE
- looks like a cell address in A1 or R1C1 style (A1 and AA11 both fail)
- starts with a number, contains spaces, or uses special characters other than underscores
- is 255 characters or longer
Placeholders follow similar rules: no spaces, no special characters except underscores, no cell-address lookalikes, and no two placeholders in the same function with the same name. Names like UNIT_PRICE and qty_sold are safe choices.
Get the formula working in a cell first
A named function is only as good as the formula inside it, so build and test the ordinary version before you save it. Here’s the example used through the rest of this article.
Priya sells handmade candles. Column B holds each candle’s price and column C holds what it cost her to make. In D2 she uses this formula to get the profit margin, with a check so an empty or zero price shows a blank instead of a divide-by-zero error:
=IF(B2=0,””,(B2-C2)/B2)
She copies it down, checks a few rows by hand (a $20 candle that cost $8 should show 0.6, or 60% once the column is formatted as a percent) and only then turns it into a named function called MARGIN.
Create the named function
- Open Named functions. In the spreadsheet, click Data > Named functions. If you already have the working formula in a cell, you can instead right-click that cell and choose View more cell actions > Define named function, which starts the same setup.
- Start a new function. Click Add new function.
- Name it. Type MARGIN in the function name box. Keep names short and descriptive; you’ll type this name often.
- Describe it. Enter something like “Profit margin as a decimal: (price minus cost) divided by price. Blank if price is 0.” This text shows up in the help box.
- Add placeholders. Add price as the first argument placeholder and cost as the second. Add them in the order you want people to enter values, then check that order in the formula help box the first time you use the function.
- Enter the formula definition. Paste the tested formula and swap each cell reference for its placeholder: =IF(price=0,””,(price-cost)/price). Google says the function expects an input for each argument you define, so use every placeholder you listed in the formula, and the formula must have matching parentheses and no misplaced commas, or Sheets won’t accept it.
- Add the details. Click Next. For price, enter a description such as “The selling price” and an example such as B2. Do the same for cost.
- Save it. Click Create. The function is now part of this spreadsheet file and ready to use in its cells.
Use it like any other function
Click an empty cell, type =MARGIN( and the help box appears with the description and argument details you wrote. Finish the formula, for example =MARGIN(B2,C2), and press Enter. Fill it down the column the same way you would any formula.
One rule surprises people: ranges written inside a formula definition are always absolute. Google’s example is that A1:B3 in a definition gets saved as an absolute range ($A$1:$B$3, with the sheet name in front), so the definition always points at the same cells no matter where you use the function. To get references that shift row by row, leave cell addresses out of the definition and pass them in as arguments instead, which is exactly what =MARGIN(B2,C2) does. If dollar signs in references are new to you, the section on subtracting the same number from every row in this walkthrough of subtraction formulas in Google Sheets shows how fixed and moving references behave.
Functions without arguments, recursion and LAMBDA
Placeholders are optional. A named function with none simply returns the result of its formula, which is handy for a fixed label or a value that several formulas share.
A named function can also call itself. Google’s own example, REVERSE_WORDS, reverses the word order in a sentence by repeatedly calling REVERSE_WORDS on the rest of the text. If a recursive function shows “Calculation limit was reached while trying to compute this formula”, the calculation took too long or used too much memory; Google’s fix is to simplify the formula.
Named functions work alongside LAMBDA and the functions that use it. Google’s COUNT_FORMULAS example counts the formulas in a range with =COUNTIF(MAP(range,LAMBDA(cell, ISFORMULA(cell))),”TRUE”). The LAMBDA function reference covers the syntax if you want to build similar ones.
If you’ve seen custom functions written in Apps Script (under Extensions > Apps Script), those are JavaScript code; named functions do the same job for formulas without any code.
Use a named function in another spreadsheet
A named function lives only in the file where you created it. To use it elsewhere, import it:
- Open the spreadsheet that should receive the function.
- Click Data > Named functions > Import function.
- Pick the spreadsheet that contains the function you want.
- Select the functions to bring over, or click Import all to take every one in that file.
- Click Import.
Three things can happen during an import:
- If the receiving file already has a function with the same name, the imported one replaces it. Check the names first if you’ve built different versions of MARGIN in different files.
- If the function depends on another named function, Sheets warns you and highlights the dependent functions, so you can import those too.
- If the function uses a formula that reaches an external source, such as IMAGE, Sheets warns you about that as well.
Google doesn’t describe any live link between the original and the imported copy. When you improve a function, import it again into each file that uses it; the newer import replaces the older one because the names match.
Exporting is not a way to share named functions. A CSV holds values only, so as this rundown of what a CSV export keeps from Google Sheets explains, formulas don’t come back when you open it again.
Edit or remove a named function
Start from Data > Named functions, where your saved functions are listed. Google’s help page doesn’t document editing or removing a named function, so look for those options beside the function’s name in that list, and after any change retest a few cells that use it.
Before you remove a function, change or delete the formulas that still call it. Google doesn’t say what those formulas show once the function is gone, so it’s safest to deal with them first.
When Sheets won’t accept or run your function
- The name is refused. Check it against the rules above. The usual culprits are a space (use an underscore), a built-in name such as AVERAGE, or a name like Q1 or AB12 that Sheets reads as a cell.
- The formula definition is refused. Count the parentheses and look for a stray comma. Pasting the formula into a normal cell first, with real cell references, is the quickest way to find the mistake.
- The name clashes with an Apps Script function. You can’t create a named function with the same name as an Apps Script custom function that already exists in the file. If the script function is added later with the same name, the named function wins.
- The result is wrong. Make sure the arguments are in the order you defined. =MARGIN(C2,B2) runs without complaint but swaps price and cost.
Named function questions that come up later
Can a named function be passed into MAP, BYROW or another LAMBDA helper?
Yes. Google’s LAMBDA reference says the reusable LAMBDA that helper functions such as MAP, BYROW and REDUCE take can be passed either as a LAMBDA function or as a named function.
What if a named range has the same name as my function?
The named range takes precedence. If a formula seems to ignore your function, check Data > Named ranges for a range with the same name and rename one of them.
Can I call a placeholder SUM or COUNT?
You can name a placeholder after a built-in function, but inside your formula definition the placeholder takes precedence, so the real SUM function stops working there. Descriptive placeholder names avoid the problem.
For a first project, pick the longest formula you’ve copied between rows this month, test it in one cell, and save it as a named function using the steps above. Google’s Create and use named functions help page has more worked examples to copy.
Matthew Burleigh has been a freelance writer since the early 2000s. You can find his writing all over the Web, where his content has collectively been read millions of times.
Matthew received his Master’s degree in Computer Science, then spent over a decade as an IT consultant for small businesses before focusing on writing and website creation.
The topics he covers for MasterYourTech.com include iPhones, Microsoft Office, and Google Apps.
You can read his full bio here.