Posts

Showing posts with the label sum

Google Script - Auto-summing non-adjacent numbers

As I previously posted, I'm working with a program in our organization that is looking to make their invoicing process more efficient.  After getting it so the invoice numbers were being automatically generated, we next wanted to auto-sum the individual item totals for a grand total. The challenges - 1. the first value wasn't until the middle of the spreadsheet, and 2. the values were not adjacent in the spreadsheet.  Luckily for us, they were an equidistant number of cells from each other (otherwise I think this script would have been a lot more complicated!).  The following script will work for a similar situation (all in grey - including the final } bracket): function totalDue() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0];  var lastRow = sheet.getLastRow();  var lastColumn = sheet.getLastColumn();  var lastCell = sheet.getRange(lastRow, lastColumn-4);  var values = sheet.getRan...