Home>

Gets the value of the specified cell and puts it in a specific cell. Then, even if the value of the specified cell is changed, the value entered before and the value entered later are continuously added.

Error message
Corresponding source code
function myFunction () {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var sh = ss.getActiveSheet ();
  sh.getRange (10, 2,10,5) .copyTo (sh.getRange (9, 2));
  sh.getRange (11, 2,11,5) .getValues ​​();// Get this number
  (2,2,2,5) // The acquired numerical value is continuously added to this range every time the script is started. I don't know how to write here

  sh.getRange (10,2,10,5) .clearContent ();
  sh.getRange (11,2,11,5) .clearContent ();
}
What I tried

Please describe here what you have tried for the problem.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    const onEdit = (e) =>{
        const watchSheetName = "Sheet 1";
        const watchCell = "B11";
        const sumCell = "B2";
        if (! e.value&&Number.isNaN (Number (e.value))) return;
        const curRange = e.range;
        const curSheet = curRange.getSheet ();
        if (curSheet! == watchSheetName) return;
        if (curRange.getA1Notation ()! == watchCell) return;
        const targetCell = curSheet.getRange (sumCell);
        targetCell.setValue (Number (targetCell.getValue ()) + Number (e.value));
    }

    Premise

    (2,2,2,5) // The acquired numerical value is continuously added to this range every time the script is started. I don't know how to write here

    About "The script starts in this range" is unclear, and getRange (2,2,2,5) represents 10 cells of B2: F3, so it is difficult to interpret even if it is added.

    Every time an input occurs in the input cell (tentatively "B11") in the sheet on an appropriate sheet (temporarily "Sheet 1"), it continues to add to the addition cell (temporarily "B2") in the sheet.

    I understood that it means.
    In line with thisgetRange (10, 2, 10, 5)(= B10: F19) andgetRange (11,2,11,5)I understand that a range like (= B11: F21) also means a separate cell like B10 or B11.
    I wondered if I wanted to add in the direction of the column, but since the range is large in B10: F19 and B11: F21, and the size of the range is also different, it is difficult to make a rational guess as to where and how to add. did.