In a google sheet, this simple script works to select a single cell, then click a button to decrease the value in the selected cell by 1:
function tally() {
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
var value = cell.getValue();
cell.setValue(value-1);
}
Is there a way to do a multiple selection - ie, select multiple / scattered cells in a table, then iterate the function in each of the selected cells?
function tally() {
const rng = SpreadsheetApp.getActiveSheet().getActiveRange();
const values = rng.getValues().map(r=>r.map(c=>c-1));
rng.setValues(values);
}
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.