function incorrect() {
const sheet = SpreadsheetApp.getActiveSheet();
const ranges = sheet.getActiveRangeList().getRanges();
const rangeList = ranges.reduce((ar, r) => {
const topRow = r.getRow();
const endRow = topRow + r.getNumRows();
const column = r.getColumn();
for (let row = topRow; row < endRow; row++) {
if (!sheet.isRowHiddenByFilter(row)) ar.push(sheet.getRange(row, column).getA1Notation());
}
return ar
}, []);
sheet.getRangeList(rangeList).setValue("updated");
}
/** * here's a workaround sketch * * because "getActiveRangeList()" and "getRange()" ignore the filtered rows * * please star issue https://issuetracker.google.com/issues/152060515 * * This workaround for this odd case provided in group forum * Thanks to Tanaike. post at * * @param newValue */const applyNewValueWorkAround = function (newValue) { newValue = "test new value"; try { const s = SpreadsheetApp.getActiveSheet(); const filter = s.getFilter(); if (filter) { //determine active rows and apply only to those SpreadsheetApp.getActiveSpreadsheet().toast('Filter detected. Beware block selections skipping large number of rows. Individually click your target cells. ');
const ranges = s.getActiveRangeList().getRanges();
const rangeList = ranges.reduce((ar, r) => { const topRow = r.getRow(); const endRow = topRow + r.getNumRows(); const column = r.getColumn(); for (let row = topRow; row < endRow; row++) {
if (!s.isRowHiddenByFilter(row)) { ar.push(s.getRange(row, column).getA1Notation()); } } return ar }, []); s.getRangeList(rangeList).setValue(newValue); } else { // apply to selected ranges s.getActiveRangeList() .getRanges().forEach(r => r.setValue(newValue)); } replyStatus = `Applied '${newValue}' to active range list.`; } catch (e) { if (e instanceof TypeError) { // Handle exception console.log(e); throw 'Logged an unexpected error applying new value to the slected cell(s); please try again.' } }};
Thank you for replying. I checked the star. When "isRowHiddenByFilter" is used, when the number of rows is large, the process cost becomes high. In this case, by using Sheets API, the cost can be reduced.A simple sample script can be seen at https://gist.github.com/tanaikech/053d3ebbe76fa7c0b5e80ea9d6396011
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/731a3b69-be27-4f42-bb03-7d61f124056a%40googlegroups.com.
Thank you for replying. Unfortunately, I cannot understand about your current situation. This is due to my poor skill. I deeply apologize for this. When I could correctly understand about your current situation and find the solution, I would like to answer it. I deeply apologize I cannot resolve your new issue soon.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ddbfcbd4-9eb2-449d-8434-0da65da3f292%40googlegroups.com.