tardy pigeon
tardy pigeon

Reputation: 225

Script for Google Sheets to copy a column daily

Every day we put all of the times our product is sent in column B of Sheet 1. Would it be possible at close of play every day (say 23:55) to copy the contents of column B to a column in Sheet 2? The big problem here is every day it would move along a column in sheet 2. So Monday would be pasted into B, Tuesday C, and so on. Basically want to use sheet 2 to keep a record of all our send times.

Upvotes: 1

Views: 2816

Answers (1)

user6655984
user6655984

Reputation:

Here is a script that copies column B of Sheet1 to a new column in Sheet2. I think the variable names and method names are self-explanatory. To have it run daily, in the script editor go to "Edit > this project's triggers" and set a time-driven trigger to run daily between 23:00 and midnight. (You don't get to choose the exact minute; it will be about the same every day but Google chooses it itself at the time of trigger creation).

function copyData() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourceRange = ss.getSheetByName("Sheet1").getRange("B:B");
  var targetSheet = ss.getSheetByName("Sheet2");
  targetSheet.insertColumnAfter(targetSheet.getLastColumn());
  var targetRange = targetSheet.getRange(1, targetSheet.getLastColumn()+1);
  sourceRange.copyTo(targetRange);
}

Upvotes: 2

Related Questions