0
votes

I know little about writing a Google script but I found this Here: Copy data from one sheet to another spreadsheet exclude specific columns

It is exactly what I am looking for

I added it to the script editor in Google Sheets

In cell A1 of Elements sheet I added =copySheet()

but I get the error

Error
You do not have permission to call setValues (line 10).

Line 10 is: dest.setValues(sourceData); of the copyTo Function

Is there a way to fix this?

Am I calling it wrong?

Thank in advance

Edit:added function

function copyTo(source,destination) {
var sourceSheet = source.getSheet();
var destSheet = destination.getSheet();
var sourceData = source.getValues();
var dest = destSheet.getRange(
destination.getRow(),        // Top row of destination
destination.getColumn(),     // left col of destination
sourceData.length,           // # rows in source
sourceData[0].length);       // # cols in source (elements in first row)
dest.setValues(sourceData);
SpreadsheetApp.flush();
}

copySheet

function copySheet() {
var sourceSheet  = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("rawElements");
var destSheet  = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Elements");

var columns_to_be_copied = ['A', 'C', 'D', 'F'];
var columns_to_be_pasted = ['A', 'B', 'C', 'D'];

for (column in columns_to_be_copied) {

  var copy_range_string = columns_to_be_copied[column] + ':' + columns_to_be_copied[column];
  var paste_range_string = columns_to_be_pasted[column] + ':' + columns_to_be_pasted[column];

  var source = sourceSheet.getRange(copy_range_string);
  var destination  = destSheet.getRange(paste_range_string);
  copyTo(source,destination );
  }
}
1

1 Answers

0
votes

In the link you provided: Copy data from one sheet to another spreadsheet exclude specific columns

There is a copyTo function defined, but in the code you pasted, this function is missing.