Home > OS >  Google Apps Scripts - Using this Script/formula for to get value for some selected Sheets in Google
Google Apps Scripts - Using this Script/formula for to get value for some selected Sheets in Google

Time:06-20

This script/formula add two adjacent columns together (Column F & G) and put it in column H for all sheets in the google sheets, I need further assistance in making it calculate only some selected sheets in google sheet. enter image description here

function runMacro() {
  const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  sheets.forEach(addFormula_);
}

function addFormula_(_sh) {    const formulaString = '=Filter(F2:F G2:G,F2:F<>"")'
  const theAddress = 'H2';
  _sh.getRange(theAddress).setFormula(formulaString);

}

CodePudding user response:

// By Name - Only Specified Sheets
function runMacro() {

  const includeSheets = [`Sheet1`, `Sheet2`, `Sheet3`, `etc`]

  SpreadsheetApp.getActiveSpreadsheet().getSheets()
                .filter(sheet => includeSheets.includes(sheet.getName()))
                .forEach(sheet => addFormula_(sheet))

}
  • Related