Google Sheets – Reference Tabs with Specific Word in COUNTIF

formulasgoogle sheetsgoogle-apps-scriptgoogle-sheets-custom-functiongoogle-sheets-query

Basically, I am trying to make a master tab that adds up all of the data from all the other tabs. These tabs are weekly breakdown numbers for ad statistic numbers, so there is a new tab added every week. Here is what every tab looks like. enter image description here The only option I have in mind to accomplish this is adding the new tab name to the formula (to be written) every time I create a new tab. However, I am wondering if there is a way to reference all tabs that contain a hyphen "-" because they are all titled with a date range separated by a hyphen. Is there any way to achieve this? Maybe even with some sort of helper column on the to-be-created master tab?

Best Answer

function SHEETLIST() {
try {
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
  var out = new Array( sheets.length+1 ) ;
  out[0] = [ "NAME" , "#GID" ];
  for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] = 
  [sheets[i-1].getName() , sheets[i-1].getSheetId() ];
  return out
}
catch( err ) {
  return "#ERROR!" 
}}

=QUERY(SHEETLIST(TODAY()), "select Col1 where Col1 contains '-'", 0)

0