how to reduce runtime of google app script that using setValues() and copyto() in forloop
I find some code and modify it for copy format copy and paste
I don't know why use it setValues() and CopyTo() but it working..
i think problem is some class in forloop. but, I don't know how to seperate setValues(),copyto() from forloop in this case
it work well but take many time by setValues() in forloop How do I seperate it from forloop for speed up
function Duplicate_Format() {
const SS = SpreadsheetApp.getActiveSpreadsheet();
const Source_NotationRange = "B6:B47";
const Target_Sheet = SS.getSheets();
const Source_Data_sheet = SpreadsheetApp.getActive().getSheetByName('01.01');
const Source_Data_Range = Source_Data_sheet.getRange(Source_NotationRange);
var Location_First = 4;
var Location_Quantity = 366;
const Location_Last = Location_First + Location_Quantity -1;
for( let j = Location_First ; j <= Location_Last; j++){
var Target_Sheets = Target_Sheet[j];
var Target_Range = Target_Sheets.getRange(Source_NotationRange);
Target_Range.setValues(Source_Data_Range.getValues());
Source_Data_Range.copyTo(Target_Range, {formatOnly:true});
}
}