0

I have a range of data on sheet5 which needs to be copied and inserted 27 columns in from the end of sheet1. I can get it to insert the column in the right place but it doesn't copy the data. I am new to scripting so any advice would be of great help.

Here is code I am using:

function store() {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();

  var source = ss.getRange ("Sheet5!D4:D80");

  var destSheet = ss.getSheetByName("Sheet1");

  var lastCol = destSheet.getLastColumn() -27;

  destSheet.insertColumnAfter(lastCol);

  source.copyTo(destSheet.getRange(lastCol + 1,1), {contentsOnly: true});

  SpreadsheetApp.getUi().alert('Played today Recorded');
}

1 Answer 1

0

Isn't it always the case. You spend hours trying to figure something out, then as soon as you ask someone the answer arrives. For anyone wondering, here is the correct code.

function store() {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();

  var source = ss.getRange ("Sheet5!D4:D80");

  var destSheet = ss.getSheetByName("Sheet1");

  var lastCol = destSheet.getLastColumn() -27;

  destSheet.insertColumnAfter(lastCol);

  source.copyTo(destSheet.getRange(4,lastCol +1,80), {contentsOnly: true});

   SpreadsheetApp.getUi().alert('Played today Recorded');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.