'How to copy filtered row?

Using Google Apps Script for Google Sheet, this formula works to copy and paste visible row 77 :

function copyRow77() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lRow = sheet.getLastRow(); 
var lCol = sheet.getLastColumn();
var range = sheet.getRange(77,1,1, lCol);
sh.insertRowsAfter(lRow, 1);
range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});
}
}

But when row 77 is filtered, it doesn't work anymore... Maybe an idea ?



Solution 1:[1]

As AsyntuBU stated:

You can use getFormulasR1C1, that will adapt to other rows/columns when copied. You can start at that. This is in no way an answer to your question, but to your comment where getFormulas wont adapt to new rows/columns

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