Ajouter un paramètre liste déroulante cascade

Bonjour

J'essaie d'ajouter une colonne pour pouvoir sélectionner un nouveau choix dans ma liste déroulante (informatique).

Voici le code que j'ai

function onEdit() {
  var classeur = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = classeur.getActiveSheet();
  var maPlage = SpreadsheetApp.getActiveRange();
  var dvListe = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("paramètres");
  var option = new Array();
  var startCol = 0;

  if(feuille.getName() == "COMPTA" && maPlage.getColumn() == 11 && maPlage.getRow() > 1){
    if(maPlage.getValue() == "frais admin"){
      startCol = 7;
    } else if(maPlage.getValue() == "locaux"){
      startCol = 8;
    } else if(maPlage.getValue() == "frais pédagogique"){
      startCol = 9;
    } else if(maPlage.getValue() == "communication"){
      startCol = 10;
    } else if(maPlage.getValue() == "commercial"){
      startCol = 11;         
    } else if(maPlage.getValue() == "autre"){
      startCol = 12; 
    } else {
      startCol = 13
    }

  if(startCol > 0 && startCol < 13){
    option = dvListe.getSheetValues(2,startCol,15,1);
    var dv = SpreadsheetApp.newDataValidation();
    dv.setAllowInvalid(false);  
    dv.setHelpText("Choisir un site en fonction de " + maPlage.getValue());
    dv.requireValueInList(option, true);
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).setDataValidation(dv.build());
   }

  if(startCol == 13){
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).clearDataValidations();
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).clearContent();
  } 
  }
}

Voici ce que j'ajoute pour insérer le nouveau choix "informatique" en décalant les colonnes suivantes.

    } else if(maPlage.getValue() == "commercial"){
      startCol = 11;

      } else if(maPlage.getValue() == "informatique"){
      startCol = 12;       

    } else if(maPlage.getValue() == "autre"){
      startCol = 13; 
    } else {
      startCol = 14
    }

  if(startCol > 0 && startCol < 14){
    option = dvListe.getSheetValues(2,startCol,15,1);
    var dv = SpreadsheetApp.newDataValidation();
    dv.setAllowInvalid(false);  
    dv.setHelpText("Choisir un site en fonction de " + maPlage.getValue());
    dv.requireValueInList(option, true);
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).setDataValidation(dv.build());
   }

  if(startCol == 13){
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).clearDataValidations();
    feuille.getRange(maPlage.getRow(),maPlage.getColumn() + 1).clearContent();
  } 
  }
}

Malheureusement, ça ne fonctionne pas. Vous sauriez me dire pourquoi?

Bonjour,

Modifie la fin : 14 au lieu de 13

    if (startCol == 14) {
      feuille.getRange(maPlage.getRow(), maPlage.getColumn() + 1).clearDataValidations();
      feuille.getRange(maPlage.getRow(), maPlage.getColumn() + 1).clearContent();
    }

Merci. Effectivement, ça a résolu le pb.

Rechercher des sujets similaires à "ajouter parametre liste deroulante cascade"