I need to copy a template row to a new range.
The template cell have contents where format, values and functions may be present.
As I was copying one row to a range of multiple rows, the functions copyValuesToRange() and copyFormatsToRange() looked good.
Essentially my code went a bit like this;
Template.copyFormatToRange(sheet, 1, lastColumn, lastRow + 1, lastRow + N);
Template.copyValuesToRange(sheet, 1, lastColumn, lastRow + 1, lastRow + N);
This copies my template row over N new rows starting at lastRow+1.
Then I noticed it was not copying the functions in the template row, e.g. =SUM(B2:C2)
I can getFunctions() to get an array that contains the functions in my template row and setFunctions() to copy them into a target ROW. An inconvenience is that I have to switch to A1 notation, which adds execution time to the script. Importantly the target range that setFunctions() writes to must be the same size as the array. This means I have to run a for loop to copy the functions over N rows.
If I am running a for loop anyway I can just use
for loop copyTo()
instead of
copyFormatToRange
copyValuesToRange
for loop to setFunctions
I was trying to avoid using copyTo() because I figured for N of certain size the single commands copy*****ToRange would be more efficient that a for loop. Am I stuck with the for loop or is there any clever way I can copy the functions form a singe row to a range of rows?