Using a Custom Function in a Google Spreadsheet?

烈酒焚心 提交于 2019-12-06 10:45:26

I had the same problem, and while the tutorial and Sum Ting Wong's answer actually do work, it didn't help in my case.

The sheet I was trying to use the custom function from was in the old format. So I converted it to the new format,created a custom function, and now I can use it the sheet.

Here's how you see if it's an old format sheet Check out the new Google Sheets

You can tell that a spreadsheet has been created in, or upgraded to, the new Google Sheets if it has a green checkmark at the bottom.

and here's how to convert it to the new format: Moving spreadsheets to the new Google Sheets

you can manually move spreadsheet contents into the new version of Sheets to take advantage of new functionality, following any of these steps:

  • Copy and paste content from a spreadsheet created in the old version to a spreadsheet created in the new version.
  • In a spreadsheet created in the old version, click the down arrow next to a sheet tab and click Copy to…, and copy the sheet (and its contents) to a spreadsheet created in the new version.
  • Export the contents from the old version and import them into a spreadsheet created in the new version.

forget the reload button hint.

if you have in the first step write your function in the script editor and save it.

 function in2mm(inNum) {               // Function to convert from INCHES to MILLIMETERS

   var outNum = 0;                     // this will hold the answer
   var factor = 25.4;                  // multiply input by this factor to get output

   if (typeof inNum != "number") {     // check to make sure input is a number
       throw "input must be a number"; // throw an exception with the error message
   }

   outNum = inNum * factor;            // calculate the answer

  return outNum;                      // return the answer to the cell which has the formula
}

for your second step write e.g. in cell A1 of your sheet, to call the function

=in2mm(10)

important is that you call your function-name started with the equal sign =

if you do a type-mismatch by your second step you get the message

#NAME?

there is no mystic and no out of date ;-) btw i imagine they talk from the browser reload button

Custom Function still work in google sheets.

function GETKWEEKDAYFROMNBR(weekdayNbr) {
    var weekdays =  ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    return weekdays[weekdayNbr];

}

usage example:

=GETKWEEKDAYFROMNBR(WEEKDAY(A2,2))

I've got the same problem. I've had a spreadsheet open for a few days and under Tools there are three script options, those being Script Gallery, Script Manager and Script Editor.

I started a new sheet and went to the script editor, and there's only two options available, just like in your image. If I select Script Gallery I get this message;

Script gallery is now the add-on store In the new Google Sheets, the script gallery has been replaced with the add-on store. Click the new Add-ons menu to get started. Learn more

The only solution I can see to get the script to work is by running it from within the script editor itself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!