2

This question merges multiple sheets of the same dimension into a single sheet using an embedded array. I need the same solution, but with a dynamic collection of sheets stored in column G.

I've tried using JOIN and CONCATENATE to first create the array as a string and then evaluate it. But there's no equivalent EVAL function in Google Sheets so I can't process this text as a formula.

=CONCATENATE("={", JOIN(";", ARRAYFORMULA("filter('" & G:G & "'!A2:F, len('" & G:G & "'!A2:A))"), "}")

I've tried using ARRAYFORMULA and INDIRECT but INDIRECT doesn't work across array ranges so this only returns the first sheet in G1:

=ARRAYFORMULA(INDIRECT("'" & G:G & "'!A2:F"))
2

2 Answers 2

0

I think you don't need "EVAL" equivalent, because there is another alternative: use a custom function instead. This function code may look like the following:

function MERGESHEETS(g) {
  if (!g || !g.length) return;  // invalid input data
  var ss = SpreadsheetApp.getActive();
  return g.reduce(function(acc, sheetName) {
    var sheet = ss.getSheetByName(sheetName[0]);
    if (sheet) {
      var values = sheet.getRange('A2:F').getValues().filter((v) => v[0]);
      acc = [...acc, ...values];
    }
    return acc;
  }, []);
}

Here you can include your dynamic data G:G as the only argument g value. More information about filter and reduce javascript functions you may find in many sources such as that.

Sign up to request clarification or add additional context in comments.

Comments

0

With the new REDUCE() function you can do this:

=REDUCE(, G:G, LAMBDA(acc, cur, VSTACK(acc, INDIRECT("'" & cur & "'!A2:F"))))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.