How To Create Your Own Function

You are here:

Creating your own function can be easier than you think.

  • Start with a new spreadsheet.
  • In the top menu select ‘Tools’ and then ‘Add function’.

Add function

  • New dialog will appear, where you can insert the name of function, arguments (unlimited number separated with commas), body of your function and description (for your use). The name can be alphanumeric characters only.

Add function

  • The function body is composed of a sequence of statements – JavaScript syntax applies. You can declare a variable with the var keyword.

var a = 5;

var b = arg1 + arg2;

var var1 = "Some string";

  • The return statement terminates the execution of the function and returns value from it.

return b;

return arg1 + arg / 2;

  • You can create private functions within your function (as it can be used in JavaScript).

function d() {
  var f = c +b;
  return f * 2;
}

  • The full example of a custom function is shown below:
Name CUSTOMFUNC1
Arguments – arg1
– arg2
– arg3
Body var a = arg1 + arg2;
var b = a * 0.5 + arg3;
var c = a*1.22 / (5 * b - (a / b));
function d() {
var f = c +b;
return f * 2;
}
return c + d();
Description Custom function example.
  • Function in action will look like this:

Custom function

  • Custom functions can be edited or deleted at any time. Just go to top menu ‘Tools’ and select ‘Manage functions.

Manage functions

  • This will show a dialog for edit or deletion.

Edit function

A tip
  • All standard functions can be used within custom function. Prefix ‘Formula‘ with a dot needs to be used before a function name:

var a = Formula.COS(arg1);