0
votes

I am working on a simple to do list that automatically moves a task over to a sheet called "Completed" when it's finished and adds a time stamp to the completed task. Everything is working, the only issue is that when the timestamp is added to the completed timestamp column, it is not formatted correctly (the center of the cell).

Any input on what could be causing this would be appreciated!

Here is my script code:

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "Uncompleted" && r.getColumn() == 1 && r.getValue() == "Yes") {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("Completed");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
    var completed = targetSheet.getRange(targetSheet.getLastRow(), 8);
    var time = s.getRange("H1").getValue();
    completed.setValue(time);
  }
 }

And you can view the working spreadsheet here:

https://docs.google.com/spreadsheet/ccc?key=0AiU2vLPIL9GldHgyRUJMMVk5TTlSQVR1cFN1Sk10Tnc&usp=sharing

2

2 Answers

0
votes

One option is to use the method copyTo(destination).

...
var completed = targetSheet.getRange(targetSheet.getLastRow(), 8);
/*var time = s.getRange("H1").getValue();
completed.setValue(time);*/
s.getRange("H1").copyTo(completed);
...
0
votes

Add the following line to your code

completed.setHorizontalAlignment("center");