google apps script - My conditional rows are coming over as a string of all data in one cell? -
here have:
var values = spreadsheetapp.getactivespreadsheet() .getsheetbyname('base').getrange('a:m').getvalues(); var row, len, data = []; (row = 0, len = values.length; row < len; row++) if (values[row][12] == 'red') data.push([values[row]]); var dest = spreadsheetapp.getactivespreadsheet() .getsheetbyname('basics'); dest.clearcontents(); var lastrow = dest.getlastrow(); dest.getrange('a1:m1').offset(lastrow, 0, data.length, data[0].length).setvalues(data);
it working, in getting data source sheet correctly, in dest, putting data cells cell a1, rather corresponding cells. doing wrong?
try code. copies without empty rows in destination sheet.
function copyvalues(){ var sheet = spreadsheetapp.getactivespreadsheet().getsheetbyname('base'); var values = sheet.getrange('a:m').getvalues(); var row, data = []; (row = 0, len = sheet.getlastrow(); row < sheet.getlastrow(); row++){ if (values[row][12] == 'red') data.push(values[row]); } var dest = spreadsheetapp.getactivespreadsheet().getsheetbyname('basics'); dest.clearcontents(); dest.getrange(1, 1, data.length, 13 ).setvalues(data); }
hope helps!
Comments
Post a Comment