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

143
Visualizações
How do you update cells based on data validation

I'm creating a budget with Google Sheets and I want to update totals based on the category. I'm using Data Validation to categorize the transactions but how would I create a button that updates all categories based on the transactions using App Scripts. Basically, I'm trying to use SUM to add everything up but only if they are categorized in a specific category. Thanks for any help that's offered.

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

0

Here's an example:

function createCategories() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  const sh1 = ss.getSheetByName('Sheet1');
  const r = SpreadsheetApp.newDataValidation().requireValueInRange(sh1.getRange('A2:A22'));
  sh.getRange(2,4,20,1).setDataValidation(r);
}

function catTotals() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  const vs = sh.getRange(2,1,sh.getLastRow() - 1,4).getValues();
  let sums ={pA:[]};
  vs.forEach((r,i) => {
    if(!sums.hasOwnProperty(r[3])) {
      sums[r[3]]=r[2];
      sums.pA.push(r[3]);
    } else {
      sums[r[3]] += r[2];
    }
  });
  let html = "<style>td,th{border:1px solid black;}</style><table><tr><th>Category</th><th>Total</th></tr>";
  sums.pA.forEach(p => {
    html += `<tr><td>${p}</td><td>${sums[p]}</td></tr>`
  });
  html += '</table><br /><input type="button" value="Exit" onClick="google.script.host.close()" />';
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),'Category Totals')
  
}

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