0
votes

I'm learning how to use the google apps scripts with google sheets, and im using the script below to test. What it basic do is call the function onEdit() and store de value before altered in vCellOld and the new value in vCellNew and then, shows a messagebox whit these two values. After tha I'm trying to store the vCellOld in the next cell on the same line but is not working. Can anyone help me with this!?

function onEdit(e)
{
  //Store the old value
  var vCellOld = e.oldValue;
  //Store the new value
  var vCellNew = e.value;
  //Shows a message box with the old and new values
  Browser.msgBox("valor antigo: " + vCellOld + " valor novo: " + vCellNew);

  //HERE SHOULD STORE THE OLD VALUE ON THE NEXT RESPECTIVE CELL
  var nCell = e.range.Offset(0,1);
  ncell.setValue(vCellOld);

}
1
I'm not aware of Range#Offset. Did you mean Range#offset? - tehhowch
Yes, but it did't work too! - Stephen Willians
Another thing that I notice, is the nCell is with c lowecase. I fixed and didn't work too! var nCell = e.range.offset(0,1); nCell.setValue(vCellOld); - Stephen Willians

1 Answers

0
votes

When you fix the errors you say you fixed, it works for me.

function onEdit(e)
{
  //Store the old value
  var vCellOld = e.oldValue;
  //Store the new value
  var vCellNew = e.value;
  //Shows a message box with the old and new values
  Browser.msgBox("Old Value: " + vCellOld + " New Value: " + vCellNew);

  //HERE SHOULD STORE THE OLD VALUE ON THE NEXT RESPECTIVE CELL
  var nCell = e.range.offset(0,1);
  nCell.setValue(vCellOld);

}

Notification

Notification

Replacement

Replacement