Add value offset 1 from active cell together in spreadsheet script?

Viewed 19

I want to to add value of cell B1 onto the existing value of A1. I would like the script to be relative, and leave the A1 cell as a pure value. Bonus if cell B1 is cleared at the end of the script.

function myFunction() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
var cellRange = sheet.getActiveCell();
var selectedColumn = cellRange.getColumn();
var selectedRow = cellRange.getRow();
var CurrentCell = cellRange.getValue ();
var RightCell = getvalue.offset(0, 1);
Logger.log(`selectedColumn: ${selectedColumn}`);
Logger.log(`selectedRow: ${selectedRow}`);
Logger.log(`selected cell vale: ${cellRange.getValue()}`);
Logger.log(`selected cell vale: ${cellRange.getValue(0, 1)}`);
cellRange.setValue(CurrentCell+RightCell);

It leaves with me with the value of A1 plus 'Range'. If A1 is 7 it returns (7Range).

Trying to do this in Google App Scripts

1 Answers

Add value of cell one column to the right to current cell.

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const r = ss.getActiveCell();
  r.setValue(r.offset(0,1).getValue() + r.getValue());
}

I get the same thing you do when I replace this with:

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const r = ss.getActiveCell();
  r.setValue(r.offset(0,1).getValue() + r);
}

And I'm kind of surprised it doesn't return an error. But yeah it returns the class name

Related