'Copy/Paste visible row whith hidden/filtered rows
I try to add a function which can copy/paste a visible row, inserting a new one in the same table. It works pretty well but not anymore with hidden rows. Error message :
"This operation does not work with ranges where one line is filtered."
Would it be possible to solve it ?
function addRow() {
var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
var lCol = sh.getLastColumn(), range = sh.getRange(lRow,1,1,lCol);
sh.insertRowsAfter(lRow, 1);
range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});
}
Solution 1:[1]
I found a formula that works well:
function copypasteRow() {
var active_range = sheet.getActiveRange();
var sh = ss.getActiveSheet(), lRow = sh.getLastRow();
var lCol = sh.getLastColumn();
sh.insertRowsAfter(lRow, 1);
active_range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
