Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
How to set quickly different notes on differents values with a script?

I would like to make a script that will set a note on each cell that have a specific value.

enter image description here

I made a script that creates new conditionnal format rule to color the cells in function of their value :

function couleurs() 
{
  var ss = SpreadsheetApp.getActive();
  var NP = ss.getSheetByName("Network Patching");
  var VLANS = ss.getSheetByName("VLANS");
  var conditionalFormatRules = NP.getConditionalFormatRules();

  let listeVlansIDBrute = VLANS.getRange(3,6, VLANS.getLastRow(),3).getValues();         //On recupere les valeurs des cellules dans la plage donnée.
  let listeCouleursBrute = VLANS.getRange(3,6, VLANS.getLastRow(),1).getBackgrounds();
  let listeFontColor = VLANS.getRange(3,6, VLANS.getLastRow(),1).getFontColors();
  
  conditionalFormatRules.splice(0, conditionalFormatRules.length)
  console.log(listeVlansIDBrute)
  console.log(listeCouleursBrute)
  for(let i=0; i<listeVlansIDBrute.length;i++)
  {
    if(listeVlansIDBrute[i][0]!=""&& listeVlansIDBrute[i][0]!=null && listeVlansIDBrute[i][3]!="" && listeCouleursBrute[i]!="#ffffff")
    {    
      NP.getRange(1,1, NP.getLastRow(), NP.getLastColumn()).activate();
      NP.setConditionalFormatRules(conditionalFormatRules);
      conditionalFormatRules = NP.getConditionalFormatRules();
      conditionalFormatRules.splice(0, 0, SpreadsheetApp.newConditionalFormatRule().setRanges([NP.getRange(1,1, NP.getLastRow(), NP.getLastColumn())])
      .whenTextEqualTo(listeVlansIDBrute[i][0]).setBackground(listeCouleursBrute[i]).setFontColor(listeFontColor[i]).build());
    }
  }
  NP.setConditionalFormatRules(conditionalFormatRules);
}

I would like to add a note on each cell, where its value has to be the associated one in the column AH. Exemple : On each cell that contains "2404", set a note with "N00-Infographie_T2" I tried to use a textFinder but it is too slow.

Do you have an other idea ? Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This script takes notes from the range 'AG6:AH8' (you can change it) and adds them to selected cells.

// menu
function onOpen() {
  SpreadsheetApp.getUi().createMenu('🛠 Scripts')
  .addItem('Add notes to selected cells', 'add_notes_to_selected_cells')
  .addToUi();
}

// main function
function add_notes_to_selected_cells() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  var notes_table = sheet.getRange('AG6:AH8').getValues(); // redefine your range
  var notes_obj = {}
  notes_table.forEach(n => notes_obj[n[0]] = n[1]);

  var active_range = sheet.getActiveRange();
  var data = active_range.getValues();
  var active_row = active_range.getRow();
  var active_col = active_range.getColumn();

  for (var row in data) {
    for (var col in data[row]) {
      try {
        var note = notes_obj[data[row][col]];
        sheet.getRange(active_row + +row,active_col+ +col).setNote(note);
      }
      catch(e) {}
    }
  }
}

The script starts via the custom menu: 'Scripts > Add notes to selected cells'. Just select any cell(s) and click on the menu:

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda