Situation: Aggregating information from several feeder Trixes and trying to populate the results from feeders to one sheet of a master Trix.
Problem: I want to write the results of each feeder trix (gathered with get_data_from_feeders() function below), to the same sheet in a Master Trix. However, each feeder array overwrites the previous feeder results, so only the last feeder trix results are shown in the Master Trix instead of all three (write_data(data) function below).
Questions:
1) How can I make each feeder set of results append the previous feeder trix results instead of overwriting them? [This will be run monthly, so each month it's okay to overwrite what had been on the sheet from last month]
2) How can I sort all of the results (I think I use .sort() but am unsure where to call it)?
Current code:
function get_data_from_feeders() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var feeders = ss.getRangeByName('spokes').getValues();
for (var i = 0; i <= feeders.length; i++) {
var feeder_id = feeders[i][0];
var feeder_open = SpreadsheetApp.openById(feeder_id);
var dataPull = feeder_open.getRangeByName('dataPull').getValues();
write_data(dataPull);
}
}
function write_data(data) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName("Forecast_Aggregation");
var dataDump = ss.getRangeByName("data_dump");
// I think the next line is where my code is incorrect - each feeder goes back to same cell instead of to the next blank row (hence, overwriting instead of appending)
ws.getRange(dataDump.getRowIndex(), 2, data.length, 20).setValues(data);
}
Thanks for your help!
Perhaps try:
function write_data(data) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName("Forecast_Aggregation");
var dataDump = ss.getRangeByName("data_dump").getRow();
var nextRow = Math.max(dataDump, ws.getLastRow())+1;
ws.getRange(nextRow, 2, data.length, 20).setValues(data);
}
You may want to review a blog of mine, too. http://blog.ditoweb.com/2012/01/consolidate-spreadsheet-sheets-with.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.