mercredi 12 décembre 2018

Adding an IF to a COLUMNTOCHECK var

I'm trying to add an "if" statement to my var COLUMNTOCHECK line so that it checks the column for a specific value, not just that something is in the cell. This is my script so far. I want to make it so that the timestamp only activates if the afformentioned column(s) contain the words "UC Phone". I want it to check if this is true in columns 5, 6, or 7.

var COLUMNTOCHECK = 5;

var DATETIMELOCATION = [0,13];

var SHEETNAME = ('December 17, 2018')

function check() {

  return true;
}

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  if( sheet.getSheetName() == SHEETNAME ) { 
    var selectedCell = ss.getActiveCell();

    if( selectedCell.getColumn() == COLUMNTOCHECK)
    { 
      var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
      dateTimeCell.setValue(new Date());

      }
  }
}

I'm pretty new to scripting in Google Sheets, so I have been working off of a code I found scouring the web.

Aucun commentaire:

Enregistrer un commentaire