0

I have a sheet with IMPORTHTML that I want to copy data from one column to a new column daily.

function saveData() {
      var spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Daily ledger'), true);
      spreadsheet.getRange('x3:x96').activate();
      spreadsheet.getRange('N3:N96').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}

This script works well, but I have to change x3:x96 every day (tomorrow I would have to change it manually to y3:y96 etc.), I also have to change the trigger date daily.

Is there a way to do it automatically? To have a script paste in a new column every day?

I know there is a way to do it in new row, but that is not what I am looking for.

1 Answer 1

0
spreadsheet.getRange(3, spreadsheet.getLastColumn()+1, 93, 1).activate();

This will activate the next right most column range from row 3 to 96.

This can also be accomplished in a more easy and in an understandable way by doing something along the lines of,

function saveData() {
    const ledger = SpreadsheetApp.getActive().getSheetByName('Daily ledger');
    ledger.getRange(3, ledger.getLastColumn()+1, 93, 1).setValues(ledger.getRange('N3:N96').getValues());
}

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.