I want an automatic timestamp to appear in column D ('Receive Date') when the value in column B ('Status') is changed to 'Received'. I have the script below, but it inserts a timestamp regardless of the status change (ie, On Order, See Notes etc.):

function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  if (sheet.getName() == "r date trial") {
    var actRng = sheet.getActiveRange();
    var editColumn = actRng.getColumn();
    var rowIndex = actRng.getRowIndex();
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
    var dateCol = headers[0].indexOf("Receive Date") + 1;
    var orderCol = headers[0].indexOf("Status") + 1;
    if (dateCol > 0 && rowIndex > 1 && editColumn == orderCol) {
      sheet.getRange(rowIndex, dateCol).setValue(Utilities.formatDate(new Date(), "UTC+8", "MM-dd-yyyy")); }

How do I change it so that the timestamp appears only when the status is marked Received? Here's the sheet if that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.