I have tested your script, and an functionally identical script in both new and old Google Spreadsheets. I can change the value of a cell in the Source sheet, run the script via the menu, then verify that the same data exists in the Destination sheet.
All of the caching issues listed involve custom functions run in a cell in the spreadsheet. Your script is only being run via a menu or the IDE when actively scripting, and would not meet the criteria for the recalculation issues listed.
You can use FILTER
on an IMPORTRANGE
, but that doesn't seem to be as 'live':
=FILTER(IMPORTRANGE("key", "Raw Data!A2:E100"), ImportRange("key", "Raw Data!C2:C100") = "Distributor")
The script that follows is intended for old Google Spreadsheets and works reliably from the IDE or a Menu. Please let me know if it doesn't work for a small data set in two new sheets.
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{name: "Copy Distributor Rows", functionName: "CopyRowsTest"}
];
ss.addMenu("Copy Rows", menuEntries);
}
function CopyRowsTest() {
var source_ss = SpreadsheetApp.getActiveSpreadsheet();
var target_ss = SpreadsheetApp.openById("xxx");
var target_sheet = target_ss.getSheetByName("Distributors");
var source_range = source_ss.getSheetByName("Raw Data").getDataRange();
var source_values = source_range.getValues();
var source_formats = source_range.getNumberFormats();
// Filter the Values
var filtered_values = source_values.filter(function (row) {
// Filter your data here
return row[2] === 'Distributor'; // Column C
});
// Append the filtered Values to the target sheet
filtered_values.forEach(function (row, r) {
// This will fix any % formatted columns caused by issue 1265
row = fixPercentFormattedColumns(row, source_formats[r]);
// Write data to Sheet
target_sheet.appendRow(row);
});
}
function fixPercentFormattedColumns(row, rowFormat) {
return row.map(function (cell, colNum) {
// Check that the format ends with %, if so return value * 100
return /%$/.test(rowFormat[colNum]) ? cell * 100 : cell;
});
}