And yet the question was about the script. I'm still successfully using the following code:
function unionRanges(e) {
var result = [];
var length = 0;
var i = 0;
try {
for (i = 0; i < arguments.length; i++)
length += arguments[i].length;
if (length > 3000) return '#BIGRANGE';
for (var i = 0; i < arguments.length; i++)
result = result.concat(arguments[i].filter(function (el) {
return el.join('').length > 0
}));
return result;
} catch (err) {
return JSON.stringify(err);
}
}
Spreadsheets feature
But, as noted above, it is easier to use {}-notation.
At first when I tried ={Sheet1!A:A; Sheet2!A:A}, I thought it didn't work because I could only see results from the first sheet. Turned out it was including all the blank cells too!
To filter out blank and empty cells while preserving duplicates (unlike =UNIQUE) and without repeating yourself (unlike =FILTER()), you can use =QUERY(), like so:
=QUERY(
{March!A1:Z; April!A2:Z; May!A2:Z},
"select * where Col1 != '' and Col1 is not null",
0)
(Note that I am including the header row from the first sheet, and omitting it from the other sheets).
If your sheets don't contain cells with empty text, you can omit Col1 != '' and.