Union multiple ranges in google sheets with programmatic lookup

后端 未结 2 1237
别跟我提以往
别跟我提以往 2021-01-24 17:43

I have a google sheet with a dynamically changing number of worksheets within it. I\'d like to be able to automatically union all worksheets that included in a named range that

2条回答
  •  情书的邮戳
    2021-01-24 18:36

    without scripts you can build a formula generator in C1 like:

    =ARRAYFORMULA({""; "={"&TEXTJOIN("; ", 1, 
     IF(A1:A="",,"QUERY("&A1:A&"!A2:C, ""where B != ''"")"))&"}"})
    

    and then copy-paste C2 wherever you need


    to skip re-copy-pasting you can use script:

    function onEdit() { 
    var sheet = SpreadsheetApp.getActive().getSheetByName("Contants");  
    var src = sheet.getRange("C2");   // The cell which holds the formula
    var str = src.getValue();
    var cell = sheet.getRange("C10");  // The cell where I want the results to be
    cell.setFormula(str);
    }
    

    so it will copy generated "formulaa"-string from C2 and it will paste it in C10 as true formula so all you need to do is type in sheet names in A column and everything gets auto-updated

    spreadsheet demo

提交回复
热议问题