1

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); 
ss.getRange("C2424").copyTo(fillDownRange);

};

TEST SHEET to reproduce issue:

https://docs.google.com/spreadsheets/d/10JL0rOyDwlFU5_vEPO5bpp8e4p1h5J9H1KJ3SzMKLqo/edit?usp=sharing

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); 

by

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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