google-apps-scriptcheckboxfiltergoogle-sheets-apifiltered

Google Sheet Script : This operation is not supported on a range with a filtered-out row


Here is my issue :

My code below does not work because of the line: current.uncheck();

And the log say : "This operation is not supported on a range with a filtered-out row."

But this sheet is not supposed to contain a filter, I also try to remove the potential filters without success.

if(current.isChecked()) // If the check box is checked
{
  // I put some data in a array :
  var arraySupport = rangeColumnToArray(ss.getSheetByName("import_support").getRange("A1:A15"))

  var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Copy of Data Bank");

  // I change criteria filter on other sheet :
  var criteriaSupport = SpreadsheetApp.newFilterCriteria()
      .setHiddenValues(arraySupport)
      .build();  
  dataSheet.getFilter().setColumnFilterCriteria(24, criteriaSupport);
  
  ss.getRange("G5:G").clearContent();  // clear eventual content
  copyExo();  // This fonction copy one column from the filtered sheet (dataSheet) on activeSheet
  activeSheet.getFilter().remove();  // I try that without success
  current.uncheck(); // And I try to uncheck the checkbox
}

Thank's for all the help you will provide me.


Solution

  • Although I'm not sure about the relationship between current and the ranges which are used in the if statement, in order to work current.uncheck(), I would like to propose the following modification.

    Modified script:

    if(current.isChecked()) // If the check box is checked
    {
      current.uncheck();  // <--- "current.uncheck();" at the last line in this function is moved to here.
      // I put some data in a array :
      var arraySupport = rangeColumnToArray(ss.getSheetByName("import_support").getRange("A1:A15"))
    

    Note: