If someone could help me understand getRange please. I have read many responses on here and the documentation here but am still confused as to how it works. (I'm a beginner coder as you can see)
How do I reference a specific row in a data set with getRange?
- I have a table of data in A1:D10
- I would like to copy one row A5:D5
I have tried the below but get an error. "number of rows in data does not match the number of rows in the range". Could someone explain how to reference a specific row?
function copyPaste() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheetByName("Sheet1");
// this is me referencing that row
var sourceRange = source.getRange("A5:D5");
// the rest
var data = sourceRange.getValues();
var lr = sourceRange.getLastRow();
var lc = sourceRange.getLastColumn();
var target = ss.getSheetByName("Sheet2")
target.getRange(target.getLastRow()+1,1,lr,lc).setValues(data);
}