Custom Functions stopped working

210 views Asked by At

I have a sheet that used a simple custom function to give me the current month as an abbreviation.

/**
* A custom function takes a # and returns a month
 *
 * @param {Number} Month #.
 * @return {String} Month Name.
 * @customfunction
 */
function MONTHNAME(input) {
  var monthvar = {
    1:'Jan',
    2:'Feb',
    3:'Mar',
    4:'Apr',
    5:'May',
    6:'Jun',
    7:'Jul',
    8:'Aug',
    9:'Sep',
    10:'Oct',
    11:'Nov',
    12:'Dec'
  }
  return monthvar[input]
}

If i copy and paste this code to a different sheet it (not a copy of this one) then it works as intended.

i would normally input it in a cell like =MONTHNAME(MONTH(TODAY()))

i have a workaround with a excel function but it looks so messy.

=IF(MONTH(TODAY()) = 1,"Jan",if(MONTH(TODAY()) = 2,"Feb",IF(MONTH(TODAY()) = 3, "Mar",if(MONTH(TODAY()) = 4,"Apr",if(MONTH(TODAY()) = 5,"May",if(MONTH(TODAY()) = 6,"Jun",if(MONTH(TODAY()) = 7,"Jul",if(MONTH(TODAY()) = 8,"Aug",if(MONTH(TODAY()) = 9,"Sep",if(MONTH(TODAY()) = 10,"Oct",if(MONTH(TODAY()) = 11,"Nov",if(MONTH(TODAY()) = 12,"Dec","-"))))))))))))

I have also tried to go to the Reference from google and i copied the double function and that also fails on this sheet.

/**
 * Multiplies the input value by 2.
 *
 * @param {number} input The value to multiply.
 * @return The input multiplied by 2.
 * @customfunction
 */
function DOUBLE(input) {
  return input * 2;
}

I have gone onto 2 different accounts removed the permissions for this script and re-added them. They run perfectly fine in the script editor's debugger.

Any advice? I don't want to have to re-set up a new spreadsheet over this.

1

There are 1 answers

0
Max Makhrov On

You may try this:

=INDEX( {"Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec"}, MONTH(TODAY()))

Your custom function may work ok, but not refresh all time as native functions do.

And vice-versa:

=MATCH("Apr", {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"},0)


Or use text fucntion:

= text(today(),"mmm")