2

I need timestamps on two different sheets to make two different dependent drop boxes work. I use the scripts below but can only get one sheet to work and not both sheets:

Script time in

function onEdit(event) {

  //SETTINGS
  var tsheet = 'In';
  var lcol = 2;
  var rcol = 8;
  var tcol = 9;
  //

  var s = event.source.getActiveSheet();
  var sname = s.getName();
  if (sname == 'In') {
    var r = event.source.getActiveRange();
    var scol = r.getColumn();
    if (scol>= lcol<=rcol) {
      s.getRange(r.getRow(), tcol).setValue(new Date());
    }
  }
}

Script Time out

function onEdit(event) {

  //SETTINGS
  var tsheet = 'Out';
  var lcol = 2;
  var rcol = 8;
  var tcol = 9;
  //

  var s = event.source.getActiveSheet();
  var sname = s.getName();
  if (sname == 'Out') {
    var r = event.source.getActiveRange();
    var scol = r.getColumn();
    if (scol>= lcol<=rcol) {
      s.getRange(r.getRow(), tcol).setValue(new Date());
    }
  }
}
1
  • Common practice is to marked the answer as best answered. Read our help center or take the tour to know more about that. Welcome to Web Applications !!
    – Jacob Jan
    Commented Mar 18, 2015 at 8:45

1 Answer 1

2

Having two onEdit scripts isn't gonna work. So try to merge the two scripts into one...

function onEdit(e) {
var s = e.source.getActiveSheet(),
    sheets = ['In', 'Out'],
    ind = sheets.indexOf(s.getName());
    if (ind === -1 || e.range.columnStart < 2 || e.range.columnStart > 8) return;
e.range.offset(0, 9 - e.range.columnStart)
    .setValue(new Date())
}

.. and see if that works ?

1
  • 1
    JPV, it works brilliantly! Really appreciate your help, after trying to figure it out myself for 2 days:) Thanks Jeroen Commented Mar 15, 2015 at 23:11

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.