'How to add two variables together in sheets script?
I'm trying to make a script that adds the value of one cell to another one before I clear the first cell. Unfortunately, all my attempts to add the second one have given errors. This is my latest one: I get a NUM error here. what do I do?1
Solution 1:[1]
You can use onEdit simple trigger, which will give you access to oldValue of cell which was edited and you can use that value to add it with column B.
Based on your this problem statement, try this sample script:-
function onEdit(e)
{
const range = e.range;
const sheet = range.getSheet();
const row = range.getRow();
const column = range.getColumn();
var oldValue = e.oldValue;
if(column === 1)
{
const colB = sheet.getRange(row,column+1); // Getting Column B value
var colB_Value = colB.getValue();
oldValue = isNaN(Number(oldValue)) ? 0 : Number(oldValue)
colB.setValue(oldValue + colB_Value) // adding old value of column A with B and setting it on Column B
}
}
Reference:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vector |
