简体   繁体   中英

Google Script Function onEdit()

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);

}

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

通知

Replacement

替代

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM