Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda