google apps script - copy values under conditions to a different sheet -
daily, add row sheet, (using onedit() , timestamp - this function not shown here) problem occurs @ end.
please see below :
my purpose copy values sheet called "payment", choosing 1 type of payment : ppal, cash, or others. (ppal in example)
function typesofpayment() { var ss = spreadsheetapp.getactivespreadsheet().getsheetbyname("john"); var rows = ss.getmaxrows();// *because add line per day, on top* var columns = ss.getmaxcolumns();// *i never add columns...* var values = ss.getrange(1,1,rows,columns).getvalues(); var target = new array(); for(i=0;i<values.length;i++) { if (values[i][2]=="ppal"){ // *if condition true copy whole row target* target.push(values[i]);// *copy whole row* } } var sdest=spreadsheetapp.getactivespreadsheet().getsheetbyname("payment"); sdest.getrange(1,1,rows,columns).setvalues(target); }
i final error message : "0 specified, waiting 8". var rows seems wrong ?
i lost. ?
thanks help. eric
modification points :
- the index of array starts 0. index of column
ppal
1. - the numbers of rows , colums
getrange()
used @setvalues()
size oftarget
used @setvalues()
.
when these reflected script, modified script follows.
modified script :
function typesofpayment() { var ss = spreadsheetapp.getactivespreadsheet().getsheetbyname("john"); var rows = ss.getmaxrows();// *because add line per day, on top* var columns = ss.getmaxcolumns();// *i never add columns...* var values = ss.getrange(1,1,rows,columns).getvalues(); var target = new array(); for(i=0;i<values.length;i++) { if (values[i][1]=="ppal"){ // *if condition true copy whole row target* target.push(values[i]);// *copy whole row* } } var sdest=spreadsheetapp.getactivespreadsheet().getsheetbyname("payment"); sdest.getrange(1,1,target.length,target[0].length).setvalues(target); }
if misunderstand question, i'm sorry.
Comments
Post a Comment