0
votes

I'm getting started on using script with Google Tables. To start I wanted to write a simple copy script which takes the values from column A and copy's it to the next free column. My problem right now is that the copyTo function doesn't work with numerical values, but the whole use next free column doesn't work with B1 Ranges or sth similar. My second thought was using a function which converts numerical range to a "normal" range, sth like convertToRange(2,1) which would return B1. But I couldn't find anything similar again.

Can anyone help me out here?

function copy () {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var source = ss.getRange ("A2:A10");
  var destColumn = ss.getLastColumn();

  source.copyTo(destColumn,1)
  source.clear ();
}
1

1 Answers

1
votes

copyTo expects a range-object (which can be obtained with row, column coordinates or with A1-Notation with the getRange() method).

Also, it may be better to provide also the name of the sheet you want to work on.

Finally, you will need to increment the "last column" index with 1 to find the first free column. See if this works

  function copy () {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  var source = ss.getRange ("A2:A10");
  var destColumn = ss.getLastColumn();
  source.copyTo(ss.getRange(1, destColumn+1))
  source.clear ();
}

Also see: getRange and copyTo.