Checkboxes as counters in multiple columns and sheets (but not al)

Viewed 19

Here is the sample sheet

What I need to do is make the checkboxes in the camera and check-in columns (green) work as a counter. When you click on checkbox, it should add one to the total of the column next to it. The trouble is that this has to work in all the sheets, but not in all the columns (I use checkboxes for other things in other columns). And the columns where that kind of data rests isnt exactly the same for all sheets.

How do I make it so that the ADD + 1 button works in a sheets, but only in the columns that I want?

Thanks for the help. Feel free to edit sheet and put code directly on it if you are willing to help.

1 Answers

You can do something like this:

function onEdit(e) {
  const sh = e.range.getSheet();
  const shn = ["Sheet0","Sheet1","Sheet2"];//you pick the sheets
  const cols = [1,5,1];//you pick the columns
  const idx = shn.indexOf(sh.getName());
  if(~idx && e.range.columnStart == cols[idx] && e.value == "TRUE") {
    e.range.offset(0,1).setValue(e.range.offset(0,1).getValue() + 1);
    e.range.setValue("FALSE");//Reset the checkbox back to false so it behaves more like a switch
  }
}
Related