This function is to copy-down a formula C2424 to the last used row. Instead of copying it down to the last used formula its copying it to the last existent row within the sheet. How can I do it only to the last row that is being used?

function copiarformulas() {

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();

var fillDownRange = ss.getRange(2424, 3, lr); 


TEST SHEET to reproduce issue:



1 Answer 1


There is a misunderstanding regarding the third parameter of getRange on var fillDownRange = ss.getRange(2424, 3, lr); as this parameter is the height of the range but what you expect is that it's the last row.

To fix your code replace

var fillDownRange = ss.getRange(2424, 3, lr); 


var fillDownRange = ss.getRange(2424, 3, lr - 2424 + 1); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.