I want to know, how to use setValue, if there are filtered rows, so that only the shown rows (C1 + one row down to last row of C) get a value.
x(){
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
sheet.getRange(C2, lastRow).setValue('x');
}
Update
It works, but very slowly. I have tested the following code and it works fast. It must start in the second shown row. The following solution works both with and without filter. What is not yet running is the second row (C2). The copied value is always inserted there. In addition I would like to do without an auxiliary cell for copying if possible. Is it possible to copy setValue for the copypaste function (getValue)?
function x() {
var spreadsheet = SpreadsheetApp.getActive();
var lastRow = spreadsheet.getLastRow();
spreadsheet.getRange('C2:'+'C'+lastRow).activate();
spreadsheet.getRange('C1').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
};
The goal is to put an x in the currently visible (not the hidden or non-visible filtered) cells of column C. For this I just need to know how to specify the second visible cell as getRange value (with offset for example), because the rest (end cell: lastRow) is working (correct selection and input, only C2, everytime, if i'm using this script, there is in C2 a x):
spreadsheet.getRange('C2:'+'C'+lastRow).activate();
The first row is fixed. How to use the first visibile not fixed row (second row) for getRange? If the last row is hidden and the script is used, no x is set there, probably because of 'C'+lastRow. This works. Only C2 is affected.
Here is the solution
var s = SpreadsheetApp.getActive().getActiveSheet();
function x() {
var lastRow = s.getLastRow();
for(var row = 2; s.isRowHiddenByFilter(row); ++row);
var range = s.getRange('C'+row+':C'+lastRow);
s.getRange('F1').copyTo(range, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…