I'm trying to copy a range from one sheet to another (whilst preserving the formulas). I wrote a simple script using copyTo
:
function copyRangeAcrossSheets(source_sheet,source_range,target_sheet,target_range) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var source_sheet = spreadsheet.getSheetByName(source_sheet);
var target_sheet = spreadsheet.getSheetByName(target_sheet);
var source_range = source_sheet.getRange(source_range);
var target_range = target_sheet.getRange(target_range);
source_range.copyTo(target_range);
}
Which I call as followed:
=copyRangeAcrossSheets("TEST_source","A1:A3","TEST_target","A1:A3")
And I'm getting the below error:
You do not have the permission to call copyTo
I did some digging around and found that functions have to use special triggers (installable) in order to modify another file. However here I'm modifying the same file.
Q1: Why is copyTo
failing here?
Q2: How can I workaround the issue without having to define installable triggers? (I just want to copy ranges whilst preserving formulas)