Brecht Parmentier
Brecht Parmentier

Reputation: 7

Copy selected range in a sheet to other place in a same sheet with Google Scripteditor

In Google Spreadsheets i try to copy some selected cells to another place in the sheet with Google Scripteditor. I have this code, but it doesn't work:

function kopieerDag() {
  var sheet = SpreadsheetApp.getActiveSheet();
  Logger.log(sheet);
  var selection = sheet.getSelection();
  // var values = selection.getValues();
  Logger.log(selection);
  selection.copyTo(sheet.getRange(1, 1), {contentsOnly: true});
}

any ideas? thx for the help!

Upvotes: 1

Views: 60

Answers (1)

Tanaike
Tanaike

Reputation: 201388

The reason of error in your script is that getSelection() is not directly returned the range object. Please use getActiveRange() for getSelection(). So can you try this modification?

From :

var selection = sheet.getSelection();

To :

var selection = sheet.getSelection().getActiveRange();

References :

Upvotes: 2

Related Questions