简体   繁体   中英

Generate a list of Sheets that meet a condition in Google Scripts?

I'd like to use Google App Script within Google Sheets to generate a list of sheet names that meet the condition of having a "Y" in a set cell across each sheet. A pseudocode example I thought about was:

>look through all sheets
>if cell "V2" on that sheet contains "Y", add the sheet's name to a list
>return the list

I just can't get my head around many of the functions in the App scripts.

function sheetNames() {
  var ss=SpreadsheetApp.getActive();
  var shts=ss.getSheets();
  var sA=[];
  for(var i=0;i<shts.length;i++) {
    var sh=shts[i];
    if(String(sh.getRange('V2').getValue()).indexOf('Y')>-1) {
      sA.push(sh.getName());
    }
  }
  return sA;
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM