Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I found the snippet below here: Re-set checkboxes to false - Google Apps Script

I'm interested in editing this to set false checkboxes to true, specifically adding to it to skip blank cells. Can't find anything helpful on skipping blanks.

function resetCheckBoxesAllSheets() {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]

var dataRange = sheet.getRange('A4:Z100');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
  for (var j = 0; j < values[i].length; j++) {
    if (values[i][j] == true) {
      values[i][j] = false;
    }
  }
}
dataRange.setValues(values);


}
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
124 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you wish to flip flop the values of a set of checkboxes this will do it for a given column active range:

Note: capitalization counts and yes those are strings. If you have any doubts about it then use your script editor's debugger to see what is in your checkboxes. That's how I figured it out when I started playing with them.

function resetCheckBoxesAllSheets() {
  var ss = SpreadsheetApp.getActive();
  var sheet=ss.getActiveSheet()
  var dataRange = sheet.getActiveRange();
  var values = dataRange.getValues();
  for (var i=0;i<values.length;i++) {
    values[i][0]=values[i][0]?"FALSE":"TRUE";
  }
  dataRange.setValues(values);
}

So in your particular case, assuming everything else in your function works then try this:

function resetCheckBoxesAllSheets() {
  var ss = SpreadsheetApp.getActive();
  var allsheets = ss.getSheets();
  for (var s in allsheets){
    var sheet=allsheets[s]
    var dataRange = sheet.getRange('A4:Z100');
    var values = dataRange.getValues();
    for (var i = 0; i < values.length; i++) {
      for (var j = 0; j < values[i].length; j++) {
        if (values[i][j]) {
          values[i][j] = "FALSE";
        }
      }
    }
    dataRange.setValues(values); 
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...