I am trying to write a Google Sheets script to copy the display values from one sheet on a workbook to another sheet on a workbook. However, I am receiving the following error message, "Exception: The number of rows in the data does not match the number of rows in the range. The data has 1 but the range has 2." Here is the code
function GEDailyData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Historical Price Data');
var sheet2 = ss.getSheetByName('Rare Current Prices');
var value2 = sheet2.getRange('C2').getDisplayValue();
var value3 = sheet2.getRange('C3').getDisplayValue();
var values = [[value2, value3]];
var range = sheet.getRange("C2:C3");
range.setValues(values);
}
I tried replacing the values2 and values3 variables in values with just "200" and "300", but I got the same error. Not sure where I am going wrong, but any help would be appreciated!
2
Answers
I figured it out. I was using the wrong syntax for the .setValues function. The correct layout for the values variable is the following:
This returns the expected result.
Try this: