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 :

first sheet

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 :

  1. the index of array starts 0. index of column ppal 1.
  2. the numbers of rows , colums getrange() used @ setvalues() size of target 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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -