I have a Google Sheet that I update with a new sheet every two days or so and title the name of the sheet the date that it is created. For organizational reasons, I do not want to combine all of the information into one sheet and parse it elsewhere, even though it would make this so much simpler.
I'd like to provide a named range of different sheet names, and have a script, function, etc go to each sheet, grab the contents of a cell and sum them. Bonus points if vlookup can be integrated to ensure that the right cell is being referenced.
So, for example:
named range = '7/3/21','7/1/21'
=sum('7/3/21'!B12,'7/1/21'!B12)
This is simple enough, but I don't want to alter this every time a new sheet is added to reference the new sheet.
In my mind it would look something like:
=sum(vlookup(A1(INDIRECT(NamedRange1&"!c1"))
where:
A1 = the name I want to lookup on the other sheets
NamedRange1 = range of cells that correspond to all of the different sheets
C1 = the cell that I want to add across all the other sheets.
function sumacellfromlistofsheets(obj) {
const listofsheets = obj.list;
const ss = SpreadsheetApp.getActive();
const shts = ss.getSheets().filter(sh => ~obj.list.indexOf(sh.getName()));
let sum = 0;
shts.forEach( sh => {
sum += sh.getRange(obj.cellinA1Notation).getValue();
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.