Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9787

Writing to Sheets when you don't know the number of rows

$
0
0

I'm attempting to write an array to Google Sheets. I'm getting my data from a datasheet and building the array based on if the item matches criteria. The problem is that I don't know how many items will be in the array.

function sortItems(){  var ss = SpreadsheetApp.getActive();  var consume = ss.getRange('Consumables').getValues();  var count = (consume.length);  var originalrow = 0;  var data = [];  do {    if(consume[originalrow][18] == "y"){      data.push(consume[originalrow]);      Logger.log(data);    }    originalrow++;  } while (originalrow < count);  ss.getRange('NewSheet!B3:Y100').setValues(data);}

When I run this it tells me "Exception: The number of rows in the data does not match the number of rows in the range. The data has 58 but the range has 98." How do I dynamically set the number of rows it will write to?


Viewing all articles
Browse latest Browse all 9787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>