1

I need to create a custom function in Google Apps Script that will allow me to input the location of certain cells and then the function would output into new cells. This is what I tried sofar:

function SetRange(RowNum) {
  var app = SpreadsheetApp;
  var ss = app.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  sheet.getActiveCell(),setValue(45)
  sheet.getRange(RowNum,24),setValue(51);

  }

I get the error that "SetValue is not defined. I am building this program as I learn so there are some facts that veteran programmers would know that I do not. Thanks again for all your help

3
  • It should be .setValue(45) not ,setValue(45). Note the use of period rather than comma. Commented Jan 26, 2018 at 16:23
  • I fixed that and got the following:Error You do not have permission to call setValue (line 6). Commented Jan 26, 2018 at 16:31
  • 1
    I see you are writing a custom function! Custom functions can only modify the cell they are being called from. More details here Commented Jan 26, 2018 at 16:41

1 Answer 1

2

Custom functions could return an array of values but can't use setValue() or setValues().

Example

function demo(){
  var output = [
    [1,2],
    [3,4]
  ]
  return output;
}

If we add =demo() to A1, the result will be:

  |  A  |  B  |
--+-----+-----+
 1|    1|    2|
 2|    3|    4|
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.