Refreshes Filter Based on Change in Another Sheet
Fri Nov 05 2021 14:00:53 GMT+0000 (Coordinated Universal Time)
Saved by
@hyfy
function onEdit(e) {
const watchName = "Temp Cost Information"; // Please set the sheet name for the sheet where data will change.
const updateName = "Temp WFP"; // Please set the sheet name for the sheet where the filter needs to update.
//Constrain onEdit to only watch the sheet we manually update.
const watchRange = e.range;
const watchSheet = watchRange.getSheet();
if (watchSheet.getSheetName() != watchName) return;
//Reapply current filter on sheet we want auto-updated.
const updateSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(updateName);
const filter = updateSheet.getFilter();
const fRange = filter.getRange();
const criterion = filter.getColumnFilterCriteria(4).copy();
filter.remove();
fRange.createFilter().setColumnFilterCriteria(4, criterion);
}
content_copyCOPY
Based on linked code to update filter when an edit is made on the same sheet.
https://stackoverflow.com/questions/67797890/refresh-a-filter-onedit-in-google-sheets-when-number-is-less-than-x/67799857#67799857
Comments