C
C
CREWbig2019-10-15 15:10:16
Google Apps Script
CREWbig, 2019-10-15 15:10:16

When changing a cell, clear cells (defined) on another sheet. How to organize?

There is a table with two sheets (Sheet1, Sheet2), data is entered in the first sheet, everything is displayed and sorted in the second sheet. I would like to implement the following:
In case of changing cells A1 - A5 to Sheet1, the contents of cells B11-B23 were cleared on Sheet2. Cells B11-B23 are checkboxes with numeric values, but that's not the point.
How to organize it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Stoyanov, 2019-10-18
@CREWbig

The algorithm is as follows:
Write the onEdit() function, condition the name of the current sheet in it, then get the active cell, check if it is in your range.
If yes, then get the second sheet, get the desired range, and clear it.

function onEdit () {
  var ss0 = SpreadsheetApp.getActiveSpreadsheet();
  
  var ss0_s1 = ss0.getActiveSheet();
  
  if ( ss0_s1.getName() === "Лист1" ) {
    var temp = ss0_s1.getActiveCell();
    var row = temp.getRow();
    var col = temp.getColumn();
    
    if ( (row >= 1 && row <= 5) && col == 1 ) {
      var ss0_s2 = ss0.getSheetByName("Лист2");
      
      ss0_s2.getRange("B11:B23").setValue("FALSE");
    }
  }
}

---
Maxim Stoyanov (stomaks), developer of Google Apps Script .
g-apps-script.com
stomaks.me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question