I have a very basic question – I am trying to populate a first empty row in Google Sheets with a hard-coded array (I will then work on populating it with data pulled from another sheet).
I keep getting the "Incorrect range width, was 14 but should be 1."
I am trying to do it using the following code:
function populateSaleData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var saleData = new Array()
saleData.push(["43376","John","Product","30","Dollars","30","yes","5","card","712.5","Adam","[email protected]","US","XYZ123456"])
var destSheet = ss.getSheetByName('Sales');
var lastFilledRowInColumnA = getLastPopulatedRow(destSheet.getRange('A:A').getValues());
var destRange = destSheet.getRange(lastFilledRowInColumnA+1,1);
destRange.setValues(saleData);
};
function getLastPopulatedRow(data) {
for (var i=data.length-1;i>=0;i--)
for (var j=0;j<data[0].length;j++)
if (data[i][j]) return i+1;
return 0;
};
I would be very grateful for any help.
destSheet.getRange(lastFilledRowInColumnA+1,1)
. In this case, each element of 2 dimensional array is required to be "1". So how about modifying todestSheet.getRange(lastFilledRowInColumnA+1,1,saleData.length,saleData[0].length)
? The reference is here. – Tanaike