Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!