Reputation: 107
Im trying to copy and paste multiple cell values to another cell on my sheet. Basically, if I edit cell "AM13", it should copy it's old value to "C23". This part is working, but the other cell, which is "N12" is not copy and pasting on cell "C25".
Here's my code right now:
function onEdit(e) {
if (e.range.getA1Notation() === 'AM13') {
var wspaste = e.source.getRange('Sheet1!C24');
var wspaste2 = e.source.getA1Notation().getRange('Sheet1!N12');
var wspaste3 = e.source.getActiveSheet().getRange('Sheet1!N12').getValue();
var OLDVALUE;
OLDVALUE = e.oldValue;
wspaste.setValue(OLDVALUE);
wspaste2.setValue(wspaste3);
}
}
Here's a copy of my sheet!
Thanks for the help!
Upvotes: 0
Views: 108
Reputation: 14537
You're using merged cells. This makes it difficult to to tell where and from where you want to get and to put values.
Probably you need something like this:
function onEdit(e) {
if (e.range.getA1Notation() === 'AM13') {
e.source.getActiveSheet().getRange('Sheet1!C24').setValue(e.oldValue);
var value = e.source.getActiveSheet().getRange('Sheet1!N13').getValue();
e.source.getActiveSheet().getRange('Sheet1!C25').setValue(value);
}
}
To debug onEdit()
function I'm used to use SpreadsheetApp.getActiveSpreadsheet().toast(value)
where value
is any value you want to check. It works almost like console.log()
or Logger.log()
For example to show the content of e.range.getA1Notation()
:
SpreadsheetApp.getActiveSpreadsheet().toast(e.range.getA1Notation())
It will show you at the bottom-right corner the window with the value:
Upvotes: 1