Home > Software design >  Checkboxes Triggering Addition Script in single row
Checkboxes Triggering Addition Script in single row

Time:02-03

In essence I'm trying to have a checkbox trigger addition. I have a number in Column A. When that number is entered checkboxes will appear in Column G. When that checkbox is checked I want it to trigger the addition function and add 1 to the same row in column A and not affect the other rows and then uncheck the checkbox.

So far, this is only working with Row 1 and not the other rows and I am not exactly sure why.

function onEdit (e) {
 checkboxes(e);
 addition(e)
}

function checkboxes(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  ui = SpreadsheetApp.getUi();
  
  var names = ss.getRange("A1:A");
  var namesValues = names.getValues();
  var checkboxes = ss.getRange("G1:G");
  var cbRows = checkboxes.getHeight();
  var cbValues = checkboxes.getValues();
    
  var newCBValues = new Array(cbRows); 
  
  for (var row = 0; row < cbRows; row  ) {
    newCBValues[row] = new Array(0); 
    if (namesValues[row] == "" || namesValues[row] == " ") { 
      newCBValues[row][0] = " "; 
     
    }else{ 
      if (cbValues[row][0] === true) {
        newCBValues[row][0] = true; 
      }else{ 
        newCBValues[row][0] = false; 
        
      }   
    }
  }
  checkboxes.setValues(newCBValues); 
  
}

function addition(e) {
  var ss = SpreadsheetApp.getActiveSheet();
  var boxey = ss.getRange("G1:G")
  var isAdd = boxey.getValue();

  if (isAdd) {
    Add();
    boxey.setValue(false);
  } 


function Add() {
var ss = SpreadsheetApp.getActiveSheet();
var numbers = ss.getRange("A1:A");

numbers.setValue(numbers.getValue() 1);
}

CodePudding user response:

Add one to column A of current row when checkbox in column G is checked

function onEdit(e) {
  if (e.range.columnStart == 7 && e.value == "TRUE") {
    const sh = e.range.getSheet();
    sh.getRange(e.range.rowStart, 1).setValue(sh.getRange(e.range.rowStart, 1).getValue()   1);
    sh.getRange(e.range.rowStart, 7).setValue("FALSE")
  }
  checkboxes(e);//your current code
  addition(e);//your current code
}
  •  Tags:  
  • Related