Reputation: 1
How do I fetch a value of one cell and add it to another cell?
I tried doing this but it only adds numbers, if I add the cell I want to add it just adds numbers in the cell.
function addProduction(){
// pop-up
Browser.msgBox("Added Net Production!");
// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("E21");
// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + "1");
}
How do you get this to work:
cell.setValue(cellValue + "D21");
Upvotes: 0
Views: 300
Reputation: 59460
Please try:
function addProduction(){
Browser.msgBox("Added Net Production!");
var cell = SpreadsheetApp.getActiveSheet().getRange("E21");
var value1 = SpreadsheetApp.getActiveSheet().getRange("D21").getValue();
var value2 = SpreadsheetApp.getActiveSheet().getRange("E21").getValue();
cell.setValue(value1 + value2);
}
Upvotes: 1