Travis
Travis

Reputation: 1284

Create a custom function for google sheets

I know it's possible to create a function in google sheets via the script editor, I used to be able to do it, now I'm struggling.
These functions should be accessible through a cell, and be able to use a cell.
How do I create a function, and how do I use it?

Upvotes: 0

Views: 290

Answers (1)

Jonathan
Jonathan

Reputation: 6537

It's all described quite extensively in the docs:

https://developers.google.com/apps-script/guides/sheets/functions

To write a custom function:

function DOUBLE(input) {
  return input * 2;
}
  1. Create or open a spreadsheet in Google Sheets.
  2. Select the menu item Tools > Script editor. If you are presented with a welcome screen, click Blank Project on the left to start a new project.
  3. Delete any code in the script editor. For the DOUBLE function above, simply copy and paste the code into the script editor.
  4. Select the menu item File > Save. Give the script project a name and click OK.
  5. All done! Now you can use the custom function.

Using a custom function:

  1. Click the cell where you want to use the function.
  2. Type an equals sign (=) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter.
  3. The cell will momentarily display Loading..., then return the result.

Upvotes: 2

Related Questions