0

I have been out of coding for a while and have forgotten much. I am attempting to read data from a selection of cells from one page and then write it to another section if it meets the criteria. Both the original section and the new section are utilizing the same number of cells, but when I attempt to write the information in the new section the output is not as desired. I have attempted:

function testertester(){
  var ss = SpreadsheetApp.getActive();
  var consume = ss.getRange('Consumables').getValues();
  var data = consume[0];
  Logger.log(data);
  ss.getRange('NewSheet!B3:Y3').setValue(data);
}

The above puts the value for [0][0] in every cell in the range. I have also attempted:

function testertester(){
  var ss = SpreadsheetApp.getActive();
  var consume = ss.getRange('Consumables').getValues();
  var data = consume[0];
  Logger.log(data);
  ss.getRange('NewSheet!B3:Y3').setValues(data);
}

This results in "Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues."

Can someone please explain what I am doing wrong.

1 Answer 1

1

Looking at the documentation for Ranges, setValues expects a two dimensional array (i.e., an array of arrays). Also looking at the documentation for Ranges, getValues returns a two dimensional array. This means you have to re-wrap your data variable.

So an amended program will look like this:

function testertester(){
  var ss = SpreadsheetApp.getActive();
  var consume = ss.getRange('Consumables').getValues();
  var data = [consume[0]]; // we now have a two dimensional array here.
  Logger.log(data);
  ss.getRange('NewSheet!B3:Y3').setValues(data);
}

This is common across all Range getters and setters that are plural. This advice should apply for all other cases where you get the error: Exception: The parameters (number[]) don't match the method signature...

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.